Amazon Interview Question

The problems are one functional and another one is DFS.