Sorting

13 articles

dsa12 min read

Merge Intervals — The Definitive Guide (LeetCode 56) [Google, Meta, Amazon, Microsoft]

Master the classic Merge Intervals problem (LeetCode 56) asked at Google, Meta, Amazon, and Microsoft. Learn why sorting by start time is the key insight, the exact overlap condition (c ≤ b), a step-by-step visual dry run, 4 common mistakes, Python and JavaScript solutions, and follow-up problems including Insert Interval, Non-overlapping Intervals, and Meeting Rooms II.

Read →
dsa6 min read

Wiggle Sort II — O(n) Virtual Index Rearrangement [LC 324]

LeetCode 324 — asked at Google and Amazon. Rearrange an array so nums[0] < nums[1] > nums[2] < nums[3]... The key insight: find the median, then use a virtual index mapping to interleave smaller and larger halves without adjacent equal elements. O(n) time with nth_element.

Read →