Amazon Interview Question

BFS search tree algorithm with conditions