TikTok interview question

both rounds asked one programming problem about trees, fairly easy