Pinterest Interview Question

Depth-first search recursion tree problem