Optiver Interview Question

Tree-related question with recursion