Meta interview question

Leet code nearest ancenstor question