TikTok Interview Question

both rounds asked one programming problem about trees, fairly easy