DEV Community

Sameer Chawla
Sameer Chawla

Posted on

🧠 LeetCode #56 (Merge Intervals) β€” Needed a Few Tries to Crack It

🧠 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++:

Failed test case

Handwritten notes

Accepted code screenshot


If you're just starting out too β€” remember: it's okay to take time. The goal is to learn.


🏷 Hashtags

LearnInPublic #Cplusplus #LeetCode #ProblemSolving #BeginnerDev #CodingJourney #DeveloperJourney #DSA #Cpp #Debugging #LeetCodeSolutions #ProblemSolvingSkills

Top comments (0)