Amazon interview question

BFS search tree algorithm with conditions