Amazon interview question

Leetcode Medium pertaining to traversals