π§ 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)