r/DSALeetCode • • 2d ago

LeetCode: 671. Second Minimum Node In a Binary Tree

Post image

Collecting every value and sorting works here, and it ignores a rule that hands you the minimum for free. Every node holds the smaller of its two children's values, so the root is always the global minimum.

That one rule does a lot of work. It also means you can skip a whole subtree as soon as you reach a value above the minimum, because nothing below it can be smaller.

One DFS pass, no collect-and-sort.

What's the strangest invariant a LeetCode tree has handed you?

Day 72/365 of my LeetCode challenge: 671. Second Minimum Node In a Binary Tree. Problem link and full breakdown in today's newsletter.

https://www.linkedin.com/pulse/leetcode-second-minimum-node-binary-tree-easy-archit-agarwal-eolmc

#LeetCode #DSA #BinaryTree #Golang

1 Upvotes

1 comment sorted by

1

u/nian2326076 2d ago

For the binary tree problem, leveraging the property of nodes to find the second minimum is a solid strategy. Consider practicing similar problems that focus on tree properties and traversal methods. You can use PracHub to explore a variety of technical questions that will enhance your understanding and problem-solving skills with tree structures.