SingleStore Interview Question

Generic algorithm question with a tree