Optiver interview question

Tree-related question with recursion