๐ง LeetCode #56 (Merge Intervals) โ Needed a Few Tries to Crack It
It took me over 2 hours and 3 failed attempts to solve [LeetCode 56: Merge Intervals].
Why?
Because sometimes the problem description and examples just arenโt enough to guide you โ and thatโs part of the challenge.
Some tricky cases like:
[[1,4],[2,3]]
[[1,4],[0,4]]
kept failing.
I assumed the intervals were always in sorted order โ they werenโt.
Then I peeked at the solution and saw:
sort(intervals.begin(), intervals.end());
That one line changed everything.
I paused, dug into how 2D sorting works in C++, and that helped unlock the logic.
๐ก What I Learned:
โ
How sorting works for 2D vectors
๐ฃ๏ธ Reading discussions and othersโ code can speed up learning
โ๏ธ Writing it by hand helped reinforce the logic
๐ธ Sharing my handwritten notes and final accepted solution in C++:
If you're just starting out too โ remember: it's okay to take time. The goal is to learn.



Top comments (0)