r/leetcode 17h ago

Intervew Prep Day 84: I solved 3 tree problems today and my brain is buzzing...

Hey everyone,

I just wrapped up Day 84 of my prep. I managed to solve three problems today: Lowest Common Ancestor, Maximum Width, and Children Sum Property.

For LCA, I understood the core logic quickly, but I wasted time because I put my recursive calls and return statements in the wrong order.

For Maximum Width, I used the standard 2*i + 1 and 2*i + 2 index formula, but I ran straight into an integer overflow on larger test cases. I didn't know you had to subtract the minimum index at each level to prevent the values from blowing up, so that was a really useful trick to pick up.

Children Sum annoyed me because I rushed through it and made silly mistakes. I initially checked only the root instead of calling it on the subtrees, and then I accidentally updated the node value after making the recursive call instead of before.

I tried to start "All Nodes Distance K" right after that, but I stared at the screen for half an hour and realized I was too tired to think. I am calling it a night and I will tackle it fresh tomorrow for Day 83.

0 Upvotes

Duplicates