r/LeetcodeChallenge • • 3h ago

STREAK🔥🔥🔥 LeetCode: 226. Invert Binary Tree

Post image
1 Upvotes

Inverting a binary tree moves entire subtrees with a single pointer swap. Nothing is copied. Mirror the left subtree, mirror the right, swap them. The tree rearranges itself in place.

The swap is the part worth picturing: one assignment moves an entire subtree with all its children.

Bonus question: can you swap before recursing instead of after? Yes. What you can't do is recurse left, swap, then recurse right.

Why does recurse-left, swap, recurse-right break it?

Day 85/365 of my LeetCode challenge: 226. Invert Binary Tree. Problem link and full breakdown in today's newsletter.

https://www.linkedin.com/pulse/leetcode-invert-binary-tree-archit-agarwal-dm6tc

#LeetCode #DSA #BinaryTree #Golang


r/LeetcodeChallenge • • 6h ago

STREAK🔥🔥🔥 LeetCode: 100. Same Tree

Post image
1 Upvotes

If you put the nil checks in the wrong order, Same Tree rejects two empty trees. p == nil || q == nil is also true when both are nil, so check both for nil first.

Same root, same left subtree, same right subtree. The recursion writes itself; the bug hides in those checks.

And compare the trees in lockstep, not their lists of values: [1,2] and [1, null,2] have the same numbers in different shapes.

Which order do you write those two nil checks in?

Day 84/365 of my LeetCode challenge: 100. Same Tree. Problem link and full breakdown in today's newsletter.

https://www.linkedin.com/pulse/leetcode-easy-same-tree-archit-agarwal-habnc

#LeetCode #DSA #BinaryTree #Golang


r/LeetcodeChallenge • • 18h ago

DISCUSS Lyft L4 Data Engineer Final Loop — Strong SQL, Partial Python. Any Chance of an Offer?

Thumbnail reddit.com
1 Upvotes

r/LeetcodeChallenge • • 21h ago

STREAK🔥🔥🔥 Day 17: worked through Largest Subarray with 0 Sum & Count Subarrays with Given XOR

Thumbnail reddit.com
1 Upvotes

r/LeetcodeChallenge • • 22h ago

STREAK🔥🔥🔥 Day 5

1 Upvotes

LC 54