Yahoo interview question

Leetcode medium/hard, Tree, Stack, HashMap