Amazon Interview Question

I was asked to solve one coding question that involved knowledge in DFS and binary trees