Solve Magic Dictionary and unknown traversal | Bloomberg Interview Question