Bloomberg Interview Question

algorithm question about tree backtracking