Binance Interview Question

Tree traversal question using javascript