Bloomberg interview question

algorithm question about tree backtracking