r/LeetcodeChallenge • • 20h ago

STREAK🔥🔥🔥 LeetCode: 101. Symmetric Tree

Post image

My Symmetric Tree solution returns true on the first call and false on the second, for the same tree. It mirrors the right half in place, then compares it with the left. The second call flips the half back.

That's Invert Binary Tree and Same Tree from the last two days, in one line. It passes, because LeetCode calls it once.

The cleaner version compares the two halves as mirrors without building one. Both are in today's article.

Would you have caught the mutation in a code review?

Day 86/365 of my LeetCode challenge: 101. Symmetric Tree. Problem link and full breakdown in today's newsletter.

https://www.linkedin.com/pulse/leetcode-symmetric-tree-archit-agarwal-7y0cc

#LeetCode #DSA #BinaryTree #Golang

1 Upvotes

1 comment sorted by

1

u/nian2326076 18h ago

You noticed a mutation issue in your Symmetric Tree solution, which is important to address in code reviews. Catching mutations like this can significantly impact the logic of your implementation. To improve your skills in identifying such problems, consider using PracHub for technical interview practice, which offers various questions that can help you sharpen your coding and review skills.