Cure.Fit interview question

It was a DFS or BFS problem