Optiver Interview Question

Tree traversals with a constraint