SingleStore interview question

Generic algorithm question with a tree