CodeWithWho (@CodeWithWho) header
CodeWithWho (@CodeWithWho) profile picture

Building software that solves real problems. Software Engineer | Frontend | Backend Shipping ideas to the internet.

Joined March 2026
Photo by CodeWithWho (@CodeWithWho)Photo by CodeWithWho (@CodeWithWho)Photo by CodeWithWho (@CodeWithWho)Photo by CodeWithWho (@CodeWithWho)Photo by CodeWithWho (@CodeWithWho)Photo by CodeWithWho (@CodeWithWho)Photo by CodeWithWho (@CodeWithWho)Photo by CodeWithWho (@CodeWithWho)Photo by CodeWithWho (@CodeWithWho)Photo by CodeWithWho (@CodeWithWho)
Don't just inspect the final answer. Watch how Sort-and-Merge builds its result in the debugger. 🎥 Watch: [LINK] Watch: youtube.com/watch?v=XgepY9ol…
2
Final result: [(0,2), (3,11)] — sorted, merged, and non-overlapping 🎥 Watch: [LINK] Watch: youtube.com/watch?v=qnd7Ubl3…
7
(3,5) + (3,10) → (3,10), then + (7,11) → (3,11) 🎥 Watch: [LINK] Watch: youtube.com/watch?v=qnd7Ubl3…
10
Overlapping intervals merge into one range: earliest start, largest endpoint 🎥 Watch: [LINK] Watch: youtube.com/watch?v=qnd7Ubl3…
6
If current_start is greater than previous_end, there is no overlap. Keep both intervals 🎥 Watch: [LINK] Watch: youtube.com/watch?v=qnd7Ubl3…
7
Append the new interval, sort everything, and process the intervals from left to right 🎥 Watch: [LINK] Watch: youtube.com/watch?v=qnd7Ubl3…
10
Sort-and-Merge costs O(n log n), but the original intervals were already sorted. Are we doing unnecessary work? 🎥 Watch: [LINK] Watch: youtube.com/watch?v=kwwNrBTK…
7
Closed intervals include endpoints. So start == previous_end also means merge 🎥 Watch: [LINK] Watch: youtube.com/watch?v=kwwNrBTK…
7
When merging overlapping intervals, use max(previous_end, current_end) to preserve the full range 🎥 Watch: [LINK] Watch: youtube.com/watch?v=kwwNrBTK…
5
If current_start is after the previous end, append. Otherwise, merge the intervals 🎥 Watch: [LINK] Watch: youtube.com/watch?v=kwwNrBTK…
5
Sort-and-Merge: append the new interval, sort everything, and merge overlaps 🎥 Watch: [LINK] Watch: youtube.com/watch?v=kwwNrBTK…
8
Booking systems, resource allocation, and AI workloads all benefit from correctly merging overlapping intervals 🎥 Watch: [LINK] Watch: youtube.com/watch?v=TJ7hITCb…
6
Sort-and-Merge sorts everything again. Linear Sweep uses the existing sorted order 🎥 Watch: [LINK] Watch: youtube.com/watch?v=TJ7hITCb…
4
Closed intervals include their endpoints. Sharing an endpoint also counts as overlap 🎥 Watch: [LINK] Watch: youtube.com/watch?v=TJ7hITCb…
7
We have sorted, non-overlapping intervals. Can we insert a new one without breaking that structure? 🎥 Watch: [LINK] Watch: youtube.com/watch?v=TJ7hITCb…
1
22
A new interval can overlap multiple existing intervals. We must merge them correctly 🎥 Watch: [LINK] Watch: youtube.com/watch?v=TJ7hITCb…
8
Brute force: O(n²) time, O(1) space. Sweep line: O(n log n) time, O(n) space. A classic space-time trade-off. Watch: youtube.com/watch?v=5tKXMRE1…
1
1
224
After sorting, the sweep visits each of the 2n endpoints once. One pass = O(n). #Algorithms Watch: youtube.com/watch?v=5tKXMRE1…
9
Sorting 2n endpoints takes O(2n log 2n), which simplifies to O(n log n). #BigO Watch: youtube.com/watch?v=5tKXMRE1…
22
n events produce 2n endpoints: one start and one end per event. Building them takes O(n). #Python Watch: youtube.com/watch?v=5tKXMRE1…
9