Optiver interview question

HackerRank - Binary Tree & basic java program