TikTok interview question

given a tree possibly order