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 435

Non-overlapping Intervals (LeetCode 435)

Target Frequency:AmazonMicrosoftGoogle

You have an array of intervals intervals, each entry [start_i, end_i]. Find the fewest intervals you'd need to delete so that whatever remains has no two intervals overlapping, and return that count.

Touching at a single boundary point does not count as overlapping -- [1, 2] and [2, 3] are considered non-overlapping.

Worked Examples

Example 1
Input:intervals = [[1,2],[2,3],[3,4],[1,3]]
Output:1
Explanation: Dropping [1,3] leaves the remaining intervals non-overlapping.
Example 2
Input:intervals = [[1,2],[1,2],[1,2]]
Output:2
Explanation: Two of the three identical [1,2] copies must go so only one [1,2] remains.
Example 3
Input:intervals = [[1,2],[2,3]]
Output:0
Explanation: These two intervals only touch at the shared point 2, so nothing needs to be removed.

⚖️Formal Constraints & Bounds

  • 1 <= intervals.length <= 105

  • intervals[i].length == 2

  • -5 * 104 <= start_i < end_i <= 5 * 104

Deep-Dive & Conceptual Insights

Core Insight

Greedy choice by earliest finish time is mathematically guaranteed to maximize non-overlapping capacity.

Real-World Scenario & Production Applications

Conference room scheduling optimization, telescope observation window allocation.

Step-by-Step Execution Trace Table

Interval (Sorted by End)prev_endConflict (start < prev_end)?ActionRemovals
[1, 2]2-Keep (initial)0
[2, 3]22 < 2 -> NoKeep, prev_end=30
[1, 3]31 < 3 -> YESRemove [1,3]1
[3, 4]33 < 3 -> NoKeep, prev_end=41
Code Shape
Archetype Code Shape
Python
1intervals.sort(key=lambda iv: iv[1])
2removed_count = 0
3prev_end = intervals[0][1]
4for start, end in intervals[1:]:
5 if start < prev_end:
6 removed_count += 1
7 else:
8 prev_end = end
9return removed_count

Conceptual Narrative

Removing the minimum number of intervals to eliminate overlaps is mathematically dual to selecting the maximum number of mutually compatible intervals via greedy earliest finish time.

🧭 Conceptual Foundation & Pattern Intuition

Given a collection of intervals, we want to find the minimum number of intervals to remove so that the remaining intervals do not overlap. Invert the problem: Min Removals=Total Intervals−Max Mutually Compatible Intervals\text{Min Removals} = \text{Total Intervals} - \text{Max Mutually Compatible Intervals}Min Removals=Total Intervals−Max Mutually Compatible Intervals This is the classic Interval Scheduling / Activity Selection Problem, famously proven solvable via a Greedy Algorithm:

  • Sort intervals by their end time (intervals.sort(key=lambda iv: iv[1])).
  • Always select the interval that finishes earliest. Why? Because finishing as early as possible leaves the maximal remaining timeline available for subsequent intervals!
  • Keep the first (earliest-finishing) interval and set prev_end to its end. For each subsequent interval:
    • If start >= prev_end, it does not conflict! Accept it and update prev_end = end.
    • If start < prev_end, it conflicts with our greedily optimal selection. It must be removed (removed_count += 1).
🎭 The Analogy: Booking a Single Stage at a Music Festival

Imagine booking indie bands on a single festival stage from noon to midnight. To pack as many bands into the day as possible, you don't book the band that starts earliest (they might play an 8-hour marathon set and block the whole afternoon). Instead, you always book the band that finishes earliest. The sooner the stage is free, the more time you preserve for future bands to perform. Every band whose set overlaps with the currently performing band must be declined.

🔑 Why It Works

Sorting by end time guarantees that every greedy retention decision is globally optimal, eliminating the need for dynamic programming and resolving the problem in O(Nlog⁡N)O(N \log N)O(NlogN) time and O(1)O(1)O(1) auxiliary space.

  • Sorting by start time instead of end time: Sorting by start time fails on long spans that start early (e.g. [1, 100] and [2, 3]); sorting by end time is mathematically proven optimal.

  • Touching boundaries are compatible: Intervals touching at borders (e.g. [1, 2] and [2, 3]) do NOT overlap per problem specification. Condition is start >= prev_end.

  • Returning retained count instead of removed count: Problem asks for removals (len(intervals) - retained or counting increments when overlapping).

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

"The fewest intervals you'd need to delete so that whatever remains has no two intervals overlapping": deleting the fewest is the same as keeping the most.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Decision rule: an interval with start < prev_end overlaps the last kept one, so it is removed; otherwise it is kept and prev_end moves to its end.

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

  • Sorting by start and keeping whichever interval comes first: on [[1,100],[2,3],[3,4]] the long [1,100] is kept and both short ones are removed (2 instead of 1).

  • Looping over all of intervals instead of intervals[1:]: the first interval is compared with its own end, start < prev_end holds, and it is counted as a removal.

The 60-Second Interview Pitch

Say this out loud before you type a single line

"I'd use Interval Scheduling. Removing the fewest intervals is the same as keeping the most, so I sort by end time and keep an interval whenever it starts at or after the end of the last one I kept, prev_end; everything else counts as removed. Keeping the interval that finishes first is safe: any best answer can swap its first interval for this one without losing room for the rest. The trap is sorting by start and keeping whoever comes first, because one long early interval then blocks several short ones: on [[1,100],[2,3],[3,4]] that removes two intervals when one is enough. Sorting is O(N log N) time, and the sort's keys take O(N) space; beyond that I only keep prev_end and the count."

Big-O Invariant Derivation

Complexity & Mathematical Proof

TIME COMPLEXITY

O(N log N)

Look at the execution steps: intervals.sort(key=lambda iv: iv[1]) takes O(N log N). The loop over intervals[1:] does O(1) work per interval: if start < prev_end, add one to removed_count; else move prev_end. The sort dominates.

SPACE COMPLEXITY

O(N) Auxiliary

Look at memory allocations: the sort with a key builds N keys and Python's sort may use up to O(N) more, so O(N). Beyond the sort, only prev_end and removed_count: O(1). (intervals[1:] also copies N - 1 references; range(1, len(intervals)) would avoid it.)

Formal Recurrence Relation

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

Derivation Progression

End-Time Sorting

O(N log N) key=lambda x: x[1]

Orders by earliest deadline to maximize remaining space for subsequent intervals.

Greedy Non-Overlap Tally

if start < prev_end: removed_count += 1 else prev_end = end

Removes the interval that overlaps the last kept one, in O(1).

Optimal Removal Bound

O(N) linear pass

Provably minimal removals.

Variable Definitions

NNN

Total number of interval requests

Memory Architecture & Bounds

🟣 Call Stack

O(1) Iterative

🔵 Auxiliary Heap

O(N) sort keys and buffer; O(1) (prev_end) beyond the sort

🟢 Output Space

O(1) Minimum removals 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 intervals to remove to make the rest non-overlapping". Classic Interval Scheduling Maximization Problem (ISMP): minimizing removals is the same as maximizing the number of compatible intervals kept. At production scale it is admission control: accept the most bookings on one resource.

CONSTRAINTS & BOUNDS

1≤intervals.length≤1051 \le intervals.length \le 10^51≤intervals.length≤105. Time budget is O(Nlog⁡N)O(N \log N)O(NlogN) sorting followed by an O(N)O(N)O(N) greedy pass.

FAANG PRODUCTION TRAPS & EDGE CASES

When requests arrive online in start order (bookings as they come in), the end-sorted greedy is not available: accepting greedily in arrival order can be far from the best. Batch the requests and sort by end, or accept that an online policy gives a weaker guarantee.

Theory Context•Intervals & Greedy
MediumLC 435

Non-overlapping Intervals (LeetCode 435)

Target Frequency:AmazonMicrosoftGoogle

You have an array of intervals intervals, each entry [start_i, end_i]. Find the fewest intervals you'd need to delete so that whatever remains has no two intervals overlapping, and return that count.

Touching at a single boundary point does not count as overlapping -- [1, 2] and [2, 3] are considered non-overlapping.

Worked Examples

Example 1
Input:intervals = [[1,2],[2,3],[3,4],[1,3]]
Output:1
Explanation: Dropping [1,3] leaves the remaining intervals non-overlapping.
Example 2
Input:intervals = [[1,2],[1,2],[1,2]]
Output:2
Explanation: Two of the three identical [1,2] copies must go so only one [1,2] remains.
Example 3
Input:intervals = [[1,2],[2,3]]
Output:0
Explanation: These two intervals only touch at the shared point 2, so nothing needs to be removed.

⚖️Formal Constraints & Bounds

  • 1 <= intervals.length <= 105

  • intervals[i].length == 2

  • -5 * 104 <= start_i < end_i <= 5 * 104

Deep-Dive & Conceptual Insights

Core Insight

Greedy choice by earliest finish time is mathematically guaranteed to maximize non-overlapping capacity.

Real-World Scenario & Production Applications

Conference room scheduling optimization, telescope observation window allocation.

Step-by-Step Execution Trace Table

Interval (Sorted by End)prev_endConflict (start < prev_end)?ActionRemovals
[1, 2]2-Keep (initial)0
[2, 3]22 < 2 -> NoKeep, prev_end=30
[1, 3]31 < 3 -> YESRemove [1,3]1
[3, 4]33 < 3 -> NoKeep, prev_end=41
Code Shape
Archetype Code Shape
Python
1intervals.sort(key=lambda iv: iv[1])
2removed_count = 0
3prev_end = intervals[0][1]
4for start, end in intervals[1:]:
5 if start < prev_end:
6 removed_count += 1
7 else:
8 prev_end = end
9return removed_count

Conceptual Narrative

Removing the minimum number of intervals to eliminate overlaps is mathematically dual to selecting the maximum number of mutually compatible intervals via greedy earliest finish time.

🧭 Conceptual Foundation & Pattern Intuition

Given a collection of intervals, we want to find the minimum number of intervals to remove so that the remaining intervals do not overlap. Invert the problem: Min Removals=Total Intervals−Max Mutually Compatible Intervals\text{Min Removals} = \text{Total Intervals} - \text{Max Mutually Compatible Intervals}Min Removals=Total Intervals−Max Mutually Compatible Intervals This is the classic Interval Scheduling / Activity Selection Problem, famously proven solvable via a Greedy Algorithm:

  • Sort intervals by their end time (intervals.sort(key=lambda iv: iv[1])).
  • Always select the interval that finishes earliest. Why? Because finishing as early as possible leaves the maximal remaining timeline available for subsequent intervals!
  • Keep the first (earliest-finishing) interval and set prev_end to its end. For each subsequent interval:
    • If start >= prev_end, it does not conflict! Accept it and update prev_end = end.
    • If start < prev_end, it conflicts with our greedily optimal selection. It must be removed (removed_count += 1).
🎭 The Analogy: Booking a Single Stage at a Music Festival

Imagine booking indie bands on a single festival stage from noon to midnight. To pack as many bands into the day as possible, you don't book the band that starts earliest (they might play an 8-hour marathon set and block the whole afternoon). Instead, you always book the band that finishes earliest. The sooner the stage is free, the more time you preserve for future bands to perform. Every band whose set overlaps with the currently performing band must be declined.

🔑 Why It Works

Sorting by end time guarantees that every greedy retention decision is globally optimal, eliminating the need for dynamic programming and resolving the problem in O(Nlog⁡N)O(N \log N)O(NlogN) time and O(1)O(1)O(1) auxiliary space.

  • Sorting by start time instead of end time: Sorting by start time fails on long spans that start early (e.g. [1, 100] and [2, 3]); sorting by end time is mathematically proven optimal.

  • Touching boundaries are compatible: Intervals touching at borders (e.g. [1, 2] and [2, 3]) do NOT overlap per problem specification. Condition is start >= prev_end.

  • Returning retained count instead of removed count: Problem asks for removals (len(intervals) - retained or counting increments when overlapping).

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

"The fewest intervals you'd need to delete so that whatever remains has no two intervals overlapping": deleting the fewest is the same as keeping the most.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Decision rule: an interval with start < prev_end overlaps the last kept one, so it is removed; otherwise it is kept and prev_end moves to its end.

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

  • Sorting by start and keeping whichever interval comes first: on [[1,100],[2,3],[3,4]] the long [1,100] is kept and both short ones are removed (2 instead of 1).

  • Looping over all of intervals instead of intervals[1:]: the first interval is compared with its own end, start < prev_end holds, and it is counted as a removal.

The 60-Second Interview Pitch

Say this out loud before you type a single line

"I'd use Interval Scheduling. Removing the fewest intervals is the same as keeping the most, so I sort by end time and keep an interval whenever it starts at or after the end of the last one I kept, prev_end; everything else counts as removed. Keeping the interval that finishes first is safe: any best answer can swap its first interval for this one without losing room for the rest. The trap is sorting by start and keeping whoever comes first, because one long early interval then blocks several short ones: on [[1,100],[2,3],[3,4]] that removes two intervals when one is enough. Sorting is O(N log N) time, and the sort's keys take O(N) space; beyond that I only keep prev_end and the count."

Big-O Invariant Derivation

Complexity & Mathematical Proof

TIME COMPLEXITY

O(N log N)

Look at the execution steps: intervals.sort(key=lambda iv: iv[1]) takes O(N log N). The loop over intervals[1:] does O(1) work per interval: if start < prev_end, add one to removed_count; else move prev_end. The sort dominates.

SPACE COMPLEXITY

O(N) Auxiliary

Look at memory allocations: the sort with a key builds N keys and Python's sort may use up to O(N) more, so O(N). Beyond the sort, only prev_end and removed_count: O(1). (intervals[1:] also copies N - 1 references; range(1, len(intervals)) would avoid it.)

Formal Recurrence Relation

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

Derivation Progression

End-Time Sorting

O(N log N) key=lambda x: x[1]

Orders by earliest deadline to maximize remaining space for subsequent intervals.

Greedy Non-Overlap Tally

if start < prev_end: removed_count += 1 else prev_end = end

Removes the interval that overlaps the last kept one, in O(1).

Optimal Removal Bound

O(N) linear pass

Provably minimal removals.

Variable Definitions

NNN

Total number of interval requests

Memory Architecture & Bounds

🟣 Call Stack

O(1) Iterative

🔵 Auxiliary Heap

O(N) sort keys and buffer; O(1) (prev_end) beyond the sort

🟢 Output Space

O(1) Minimum removals 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 intervals to remove to make the rest non-overlapping". Classic Interval Scheduling Maximization Problem (ISMP): minimizing removals is the same as maximizing the number of compatible intervals kept. At production scale it is admission control: accept the most bookings on one resource.

CONSTRAINTS & BOUNDS

1≤intervals.length≤1051 \le intervals.length \le 10^51≤intervals.length≤105. Time budget is O(Nlog⁡N)O(N \log N)O(NlogN) sorting followed by an O(N)O(N)O(N) greedy pass.

FAANG PRODUCTION TRAPS & EDGE CASES

When requests arrive online in start order (bookings as they come in), the end-sorted greedy is not available: accepting greedily in arrival order can be far from the best. Batch the requests and sort by end, or accept that an online policy gives a weaker guarantee.

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