Pinterest interview question

Depth-first search recursion tree problem