Hi👋SpeedAlgo • Deliberate Practice & Cognitive Ergonomics for Software Engineers

An interactive algorithm mastery and technical interview preparation platform published by Hi👋WebEnterprise. Built for senior and staff software engineers preparing for rigorous coding screens at top tech companies (FAANG/MAMAA).

13 Core Algorithmic Patterns & 225 Practice Problems

  • 1. Two Pointers (16 Paradigms, 43 Problems): Opposite ends, sorted pair sums, palindrome verification, trapping rain water, 3Sum, container with most water — includes the Sliding Window and Fast & Slow Pointers paradigms (contiguous subarray invariants, longest substrings, Floyd's cycle detection, linked list middle).
  • 2. Binary Search (9 Paradigms, 14 Problems): Monotonic predicate partitioning (feasible(x)), boundary search, rotated sorted arrays, square roots, minimum ship capacity, median of two sorted arrays, matrix median on value range.
  • 3. Bit Manipulation (5 Paradigms, 11 Problems): Counting set bits, XOR cancellation, bit reversal, bitmask pairing, maximum XOR with a bitwise trie.
  • 4. Math & Geometry (8 Paradigms, 14 Problems): Sieve of Eratosthenes, integer/roman conversions, modular arithmetic, geometric simulation.
  • 5. Tree/Graph Depth-First Search (15 Paradigms, 24 Problems): Path sums, lowest common ancestor, tree diameter, validating BSTs, tree DP (House Robber III, Binary Tree Cameras).
  • 6. Tree/Graph Breadth-First Search (5 Paradigms, 12 Problems): Level-order traversals, shortest path in unweighted graphs, zig-zag traversals, rotting oranges, word ladders.
  • 7. Graphs (12 Paradigms, 22 Problems): Topological sort, cycle detection, Dijkstra's algorithm, bipartite graph validation, network delay.
  • 8. Backtracking (6 Paradigms, 14 Problems): Subsets, permutations, combinations, constraint satisfaction, pruning, N-Queens, Sudoku solver.
  • 9. Dynamic Programming (13 Paradigms, 28 Problems): Memoization vs tabulation, 0/1 knapsack, unbounded knapsack, coin change, edit distance, longest common subsequence.
  • 10. Heap / Priority Queue (9 Paradigms, 11 Problems): Running medians, top-k elements, interval scheduling, IPO, k-way merges.
  • 11. Advanced Data Structures (7 Paradigms, 17 Problems): Trie (prefix tree), Union-Find (Disjoint Set Union), LRU Cache, LFU Cache, range-sum queries with updates.
  • 12. Stack (5 Paradigms, 9 Problems): Next greater element, largest rectangle in histogram, remove k digits, decode string, min stack.
  • 13. Intervals & Greedy (2 Paradigms, 6 Problems): Merge intervals, interval scheduling, meeting rooms by sweep line, jump game.

4-Stage Deliberate Practice Framework

  1. Stage 1 (Compare & Learn): Read the pattern's mental model, loop invariant and Big-O proof, compare the pattern's template with the problem's solution side by side, and use the step-by-step debugger. The solution can also be shown in C#, Java, TypeScript, C++, Go or Rust for almost every problem.
  2. Stage 2 (Active Recall): Rebuild the solution from memory in a code editor, with an invariant checklist and optional progressive hints, and check it against a judged test suite.
  3. Stage 3 (AI Interview Coach, coming soon): A mock-interview stage still in development; for now, students go straight from Stage 2 to Stage 4.
  4. Stage 4 (Solve on Your Own): Solve a new problem on your own against a 15-minute timer; your code is graded against a test suite. Python and TypeScript run in your browser and C# runs on our server (design problems grade in Python and TypeScript).

Equipped with a spaced-repetition review hub on a fixed 7-step schedule (1 day up to 90 days), a two-pane Studio workspace, and study notes.

Pricing, Access & Commercial Terms

  • Core Curriculum: 100% Free. No credit card required.
  • Coins: New accounts get 40 free coins once, the daily claim adds +20 coins once a day, and inviting a friend earns you +25 coins when they complete their first practice step. These are the only ways to earn coins.
  • AI Coach: Each AI coach question costs 1-5 coins, priced by the server according to its size.
  • BYOK (Bring Your Own Key): AI coaching is free with your own Google Gemini, OpenAI or OpenRouter API key (BYOK).
  • Extras: Coins also unlock extras for 24 hours: a Recall hint level (1 coin), a Solve solution reveal (2), a LeetCode problem card's solutions (1) and a pattern's extra canonical problems (1).
  • Payments & Refunds: Nothing on the site is sold for money: coins can only be earned, never bought. There are no subscriptions or charges, so there is nothing to refund.
  • Platform Operator: Hi👋WebEnterprise. Support & policies at hispeedalgo.com.
Skip to main content
Hi👋SpeedAlgo

Invariant-First Algorithmic Mastery

Arena
238Items
Theory Context•Intervals & Greedy
MediumLC 253

Meeting Rooms II (LeetCode 253)

Target Frequency:GoogleMetaAmazon

You're given an array of meeting time intervals intervals, each entry [start_i, end_i]. Figure out the smallest number of conference rooms that lets every meeting happen -- no room may host two meetings whose times actually overlap (a meeting ending at end_i and another starting at start_j don't overlap once end_i <= start_j).

Worked Examples

Example 1
Input:intervals = [[0,30],[5,10],[15,20]]
Output:2
[0, 30][5, 10][15, 20]030
Explanation: [0,30] overlaps both other meetings, but those two do not overlap each other, so 2 rooms are enough.
Example 2
Input:intervals = [[7,10],[2,4]]
Output:1
[7, 10][2, 4]210
Explanation: The two meetings do not overlap, so one room is enough.

⚖️Formal Constraints & Bounds

  • 1 <= intervals.length <= 104

  • 0 <= start_i < end_i <= 106

Deep-Dive & Conceptual Insights

Core Insight

A min-heap dynamically discovers and reuses the earliest-vacated room in logarithmic time.

Real-World Scenario & Production Applications

Cloud compute VM instance auto-scaling, conference room booking, and airport gate scheduling.

Step-by-Step Execution Trace Table

StepMeeting IntervalRooms Heap Beforerooms[0] <= start?Action TakenRooms Heap AfterActive Room Count
1[0, 30][]—Open Room 1 ending at 30[30]1
2[5, 10][30]30 <= 5 (False)All rooms busy →\to→ Open Room 2[10, 30]2
3[15, 20][10, 30]10 <= 15 (True)Room 2 free! Pop 10, Push 20 (Reuse Room 2)[20, 30]2
Code Shape
Archetype Code Shape
Python
1events = []
2for start, end in intervals:
3 events.append((start, 1))
4 events.append((end, -1))
5events.sort(key=lambda ev: (ev[0], ev[1]))
6active_rooms = 0
7max_rooms = 0
8for time, delta in events:
9 active_rooms += delta
10 max_rooms = max(max_rooms, active_rooms)
11return max_rooms

Conceptual Narrative

Merge Intervals tracks continuous busy periods; Meeting Rooms II tracks peak concurrent overlap. Turning every meeting into a +1 event at its start and a -1 event at its end, then sweeping the sorted events, finds the minimum room count in O(N log N) time.

🧭 Conceptual Foundation & Pattern Intuition

The minimum number of conference rooms required equals the maximum number of meetings taking place concurrently at any single point in time. That number only changes at two kinds of moments: a meeting starts (one more room in use) or a meeting ends (one room freed). So we never need to know which room a meeting gets:

  • Each interval [start, end] becomes two events: (start, 1) and (end, -1).
  • Sort the events by time. On a tie, the -1 must come first: meetings are half-open [start, end), so a meeting ending at 10 frees its room before a meeting starting at 10 needs one. Sorting by (time, delta) does this, because -1 < 1.
  • Sweep the sorted events, adding each delta to active_rooms. The largest value active_rooms ever reaches (max_rooms) is the answer.
🚪 The Analogy: The Turnstile Counter

Picture a turnstile at the door of the meeting floor. Every time someone's meeting starts, the counter clicks up by one; every time a meeting ends, it clicks down by one. The building manager does not care who is in which room, only the highest number the counter ever showed during the day: that is how many rooms the floor needs. When one meeting ends at the exact moment another starts, the leaving group goes out before the arriving group comes in, so the counter does not rise by one for that instant.

🔑 Why It Works

Only the running count matters, so the start and end of the same meeting never need to stay together once they are events. The tie order is the one detail that is easy to get wrong: with starts first, [[5, 10], [10, 20]] would report 2 rooms instead of 1.

  • Sorting the intervals instead of the events: sorting intervals by start or by end does not order the individual start and end moments; build the events list first, then sort the events.

  • Starts before ends on a tie: meetings are half-open [start, end), so at a shared time the -1 event must be applied before the +1. Sorting by (time, delta) does this because -1 < 1; putting starts first makes [[5, 10], [10, 20]] report 2 rooms instead of 1.

  • Tracking room identities: the answer only needs the running count active_rooms; each meeting becomes two independent events, (start, 1) and (end, -1), and max_rooms keeps the highest count.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

"The minimum number of conference rooms required": a room is needed for every meeting that is on at the same moment, so the answer is the largest number of meetings that overlap at any one time.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Decision rule: each event changes active_rooms by its delta, and right after every change max_rooms = max(max_rooms, active_rooms).

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

  • Treating a meeting that ends at time T and one that starts at time T as overlapping: they can share the room. Sorting events by time alone keeps whatever order they were appended in, so a start can be counted before the end it should replace; sort by (time, delta) so the -1 comes first.

  • Returning active_rooms instead of max_rooms: after the last event every meeting has ended, so active_rooms is always 0.

The 60-Second Interview Pitch

Say this out loud before you type a single line

"I'd use a Sweep Line. Each meeting becomes two events: plus one at its start and minus one at its end. I sort the events by time and add them up in order, so the running total, active_rooms, is how many meetings are on at that moment, and its highest value, max_rooms, is how many rooms I need. That is correct because the count only changes at an event, so checking right after each event sees every value it ever takes. The trap is a tie: when one meeting ends as another starts, the minus one must come first, and sorting by time and then delta does that because minus one is smaller than plus one. Time is O(N log N) for the sort, and space is O(N) for the 2N events."

Big-O Invariant Derivation

Complexity & Mathematical Proof

TIME COMPLEXITY

O(N log N)

Look at the execution steps: the first loop appends two events per meeting, 2N appends in O(N). events.sort(key=lambda ev: (ev[0], ev[1])) sorts the 2N events in O(N log N). The last loop does O(1) work per event, 2N steps. The sort dominates.

SPACE COMPLEXITY

O(N) Auxiliary

Look at memory allocations: events holds 2N tuples, O(N), and Python's sort may use up to O(N) more. Beyond that only the two counters active_rooms and max_rooms; the output is one integer.

Formal Recurrence Relation

T(N) = O(N) + O(2N log 2N) + O(2N) = O(N log N)

Derivation Progression

Build Events

events.append((start, 1)); events.append((end, -1))

Two O(1) appends per meeting: O(N) for all N meetings.

Sort Events

events.sort(key=lambda ev: (ev[0], ev[1]))

Sorting 2N events takes O(N log N); on a tie the -1 sorts first.

Sweep

active_rooms += delta; max_rooms = max(max_rooms, active_rooms)

O(1) per event, 2N events: O(N).

Variable Definitions

NNN

Total number of meeting intervals (2N events)

Memory Architecture & Bounds

🟣 Call Stack

O(1) Iterative

🔵 Auxiliary Heap

O(N) events list of 2N tuples

🟢 Output Space

O(1) Peak room count integer

Boundary Best / Worst Cases

Best Case

O(Nlog⁡N)O(N \log N)O(NlogN)

Average Case

O(Nlog⁡N)O(N \log N)O(NlogN)

Worst Case

O(Nlog⁡N)O(N \log N)O(NlogN)

Recurrence Tree Topology

Recurrence Tree Topology
Synthesizing vector architecture diagram...
Staff+ Engineering Perspective

Senior SWE Deconstruction & Hardware Caveats

ARCHITECTURAL SIGNALS & INTERVIEW TRIGGERS

Triggers: "minimum number of conference rooms required", "maximum concurrent overlapping intervals". At production scale the same question is asked as peak concurrency: the most sessions, bookings or connections alive at one moment.

CONSTRAINTS & BOUNDS

1≤intervals.length≤1041 \le intervals.length \le 10^41≤intervals.length≤104, so at most 2⋅1042 \cdot 10^42⋅104 events. Time budget: O(Nlog⁡N)O(N \log N)O(NlogN) for the sort. Space budget: O(N)O(N)O(N) for events.

FAANG PRODUCTION TRAPS & EDGE CASES

A live stream of bookings cannot be sorted once up front. Re-sorting the whole events list on every new booking costs O(Nlog⁡N)O(N \log N)O(NlogN) per insert; keep a sorted map from time to net delta instead, or count per time bucket when the time range is small.

Core Algorithmic State Invariants

  1. Only Event Times Matter

Between two event times nothing starts or ends, so the number of meetings in progress stays the same. Checking active_rooms right after each event therefore sees every value it ever takes, including the peak.

  1. The Peak Is Exactly the Room Count

At the peak moment max_rooms meetings are on at once, so no schedule can use fewer rooms. And giving each starting meeting any room that is free never needs more rooms than are busy at that moment, so max_rooms rooms are always enough.

  1. Counting, Not Assigning

events does not record which meeting each event came from, which is what keeps the sweep simple. If a problem also asks which room each meeting gets, the count alone is not enough: each meeting must be matched to a specific free room.

Theory Context•Intervals & Greedy
MediumLC 253

Meeting Rooms II (LeetCode 253)

Target Frequency:GoogleMetaAmazon

You're given an array of meeting time intervals intervals, each entry [start_i, end_i]. Figure out the smallest number of conference rooms that lets every meeting happen -- no room may host two meetings whose times actually overlap (a meeting ending at end_i and another starting at start_j don't overlap once end_i <= start_j).

Worked Examples

Example 1
Input:intervals = [[0,30],[5,10],[15,20]]
Output:2
[0, 30][5, 10][15, 20]030
Explanation: [0,30] overlaps both other meetings, but those two do not overlap each other, so 2 rooms are enough.
Example 2
Input:intervals = [[7,10],[2,4]]
Output:1
[7, 10][2, 4]210
Explanation: The two meetings do not overlap, so one room is enough.

⚖️Formal Constraints & Bounds

  • 1 <= intervals.length <= 104

  • 0 <= start_i < end_i <= 106

Deep-Dive & Conceptual Insights

Core Insight

A min-heap dynamically discovers and reuses the earliest-vacated room in logarithmic time.

Real-World Scenario & Production Applications

Cloud compute VM instance auto-scaling, conference room booking, and airport gate scheduling.

Step-by-Step Execution Trace Table

StepMeeting IntervalRooms Heap Beforerooms[0] <= start?Action TakenRooms Heap AfterActive Room Count
1[0, 30][]—Open Room 1 ending at 30[30]1
2[5, 10][30]30 <= 5 (False)All rooms busy →\to→ Open Room 2[10, 30]2
3[15, 20][10, 30]10 <= 15 (True)Room 2 free! Pop 10, Push 20 (Reuse Room 2)[20, 30]2
Code Shape
Archetype Code Shape
Python
1events = []
2for start, end in intervals:
3 events.append((start, 1))
4 events.append((end, -1))
5events.sort(key=lambda ev: (ev[0], ev[1]))
6active_rooms = 0
7max_rooms = 0
8for time, delta in events:
9 active_rooms += delta
10 max_rooms = max(max_rooms, active_rooms)
11return max_rooms

Conceptual Narrative

Merge Intervals tracks continuous busy periods; Meeting Rooms II tracks peak concurrent overlap. Turning every meeting into a +1 event at its start and a -1 event at its end, then sweeping the sorted events, finds the minimum room count in O(N log N) time.

🧭 Conceptual Foundation & Pattern Intuition

The minimum number of conference rooms required equals the maximum number of meetings taking place concurrently at any single point in time. That number only changes at two kinds of moments: a meeting starts (one more room in use) or a meeting ends (one room freed). So we never need to know which room a meeting gets:

  • Each interval [start, end] becomes two events: (start, 1) and (end, -1).
  • Sort the events by time. On a tie, the -1 must come first: meetings are half-open [start, end), so a meeting ending at 10 frees its room before a meeting starting at 10 needs one. Sorting by (time, delta) does this, because -1 < 1.
  • Sweep the sorted events, adding each delta to active_rooms. The largest value active_rooms ever reaches (max_rooms) is the answer.
🚪 The Analogy: The Turnstile Counter

Picture a turnstile at the door of the meeting floor. Every time someone's meeting starts, the counter clicks up by one; every time a meeting ends, it clicks down by one. The building manager does not care who is in which room, only the highest number the counter ever showed during the day: that is how many rooms the floor needs. When one meeting ends at the exact moment another starts, the leaving group goes out before the arriving group comes in, so the counter does not rise by one for that instant.

🔑 Why It Works

Only the running count matters, so the start and end of the same meeting never need to stay together once they are events. The tie order is the one detail that is easy to get wrong: with starts first, [[5, 10], [10, 20]] would report 2 rooms instead of 1.

  • Sorting the intervals instead of the events: sorting intervals by start or by end does not order the individual start and end moments; build the events list first, then sort the events.

  • Starts before ends on a tie: meetings are half-open [start, end), so at a shared time the -1 event must be applied before the +1. Sorting by (time, delta) does this because -1 < 1; putting starts first makes [[5, 10], [10, 20]] report 2 rooms instead of 1.

  • Tracking room identities: the answer only needs the running count active_rooms; each meeting becomes two independent events, (start, 1) and (end, -1), and max_rooms keeps the highest count.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

"The minimum number of conference rooms required": a room is needed for every meeting that is on at the same moment, so the answer is the largest number of meetings that overlap at any one time.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Decision rule: each event changes active_rooms by its delta, and right after every change max_rooms = max(max_rooms, active_rooms).

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

  • Treating a meeting that ends at time T and one that starts at time T as overlapping: they can share the room. Sorting events by time alone keeps whatever order they were appended in, so a start can be counted before the end it should replace; sort by (time, delta) so the -1 comes first.

  • Returning active_rooms instead of max_rooms: after the last event every meeting has ended, so active_rooms is always 0.

The 60-Second Interview Pitch

Say this out loud before you type a single line

"I'd use a Sweep Line. Each meeting becomes two events: plus one at its start and minus one at its end. I sort the events by time and add them up in order, so the running total, active_rooms, is how many meetings are on at that moment, and its highest value, max_rooms, is how many rooms I need. That is correct because the count only changes at an event, so checking right after each event sees every value it ever takes. The trap is a tie: when one meeting ends as another starts, the minus one must come first, and sorting by time and then delta does that because minus one is smaller than plus one. Time is O(N log N) for the sort, and space is O(N) for the 2N events."

Big-O Invariant Derivation

Complexity & Mathematical Proof

TIME COMPLEXITY

O(N log N)

Look at the execution steps: the first loop appends two events per meeting, 2N appends in O(N). events.sort(key=lambda ev: (ev[0], ev[1])) sorts the 2N events in O(N log N). The last loop does O(1) work per event, 2N steps. The sort dominates.

SPACE COMPLEXITY

O(N) Auxiliary

Look at memory allocations: events holds 2N tuples, O(N), and Python's sort may use up to O(N) more. Beyond that only the two counters active_rooms and max_rooms; the output is one integer.

Formal Recurrence Relation

T(N) = O(N) + O(2N log 2N) + O(2N) = O(N log N)

Derivation Progression

Build Events

events.append((start, 1)); events.append((end, -1))

Two O(1) appends per meeting: O(N) for all N meetings.

Sort Events

events.sort(key=lambda ev: (ev[0], ev[1]))

Sorting 2N events takes O(N log N); on a tie the -1 sorts first.

Sweep

active_rooms += delta; max_rooms = max(max_rooms, active_rooms)

O(1) per event, 2N events: O(N).

Variable Definitions

NNN

Total number of meeting intervals (2N events)

Memory Architecture & Bounds

🟣 Call Stack

O(1) Iterative

🔵 Auxiliary Heap

O(N) events list of 2N tuples

🟢 Output Space

O(1) Peak room count integer

Boundary Best / Worst Cases

Best Case

O(Nlog⁡N)O(N \log N)O(NlogN)

Average Case

O(Nlog⁡N)O(N \log N)O(NlogN)

Worst Case

O(Nlog⁡N)O(N \log N)O(NlogN)

Recurrence Tree Topology

Recurrence Tree Topology
Synthesizing vector architecture diagram...
Staff+ Engineering Perspective

Senior SWE Deconstruction & Hardware Caveats

ARCHITECTURAL SIGNALS & INTERVIEW TRIGGERS

Triggers: "minimum number of conference rooms required", "maximum concurrent overlapping intervals". At production scale the same question is asked as peak concurrency: the most sessions, bookings or connections alive at one moment.

CONSTRAINTS & BOUNDS

1≤intervals.length≤1041 \le intervals.length \le 10^41≤intervals.length≤104, so at most 2⋅1042 \cdot 10^42⋅104 events. Time budget: O(Nlog⁡N)O(N \log N)O(NlogN) for the sort. Space budget: O(N)O(N)O(N) for events.

FAANG PRODUCTION TRAPS & EDGE CASES

A live stream of bookings cannot be sorted once up front. Re-sorting the whole events list on every new booking costs O(Nlog⁡N)O(N \log N)O(NlogN) per insert; keep a sorted map from time to net delta instead, or count per time bucket when the time range is small.

Core Algorithmic State Invariants

  1. Only Event Times Matter

Between two event times nothing starts or ends, so the number of meetings in progress stays the same. Checking active_rooms right after each event therefore sees every value it ever takes, including the peak.

  1. The Peak Is Exactly the Room Count

At the peak moment max_rooms meetings are on at once, so no schedule can use fewer rooms. And giving each starting meeting any room that is free never needs more rooms than are busy at that moment, so max_rooms rooms are always enough.

  1. Counting, Not Assigning

events does not record which meeting each event came from, which is what keeps the sweep simple. If a problem also asks which room each meeting gets, the count alone is not enough: each meeting must be matched to a specific free room.

© 2026 Hi👋WebEnterprise. All rights reserved.
Sitemap•llms.txt•