TikTok Interview Question

a tricky binary tree problem that took me 90min to solve