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•Priority Queue / Heap
HardLC 502

IPO (LeetCode 502)

Target Frequency:MetaAppleAmazon

Imagine the company LeetCode wants to raise money through an IPO, and to make itself more attractive to investors it first wants to grow its capital by completing some projects. It only has the resources to complete at most k of them before the IPO. Help LeetCode pick the projects that grow its capital the most.

You're given n available projects. The i-th project pays out pure profit profits[i], but needs a minimum capital of capital[i] in hand before it can even be started.

You start with w capital, and every completed project's profit gets folded straight back into your capital, growing what you can afford to fund next.

Choose up to k distinct projects so that your final capital ends up as large as possible, and return that maximized amount.

Worked Examples

Example 1
Input:k = 2, w = 0, profits = [1,2,3], capital = [0,1,1]
Output:4
Explanation: You start with 0 capital, so project 0 (needing 0 capital) is the only one you can afford; completing it raises your capital to 1. That capital now unlocks either project 1 or project 2 -- picking the more profitable one, project 2, brings your total to 0 + 1 + 3 = 4.
Example 2
Input:k = 3, w = 0, profits = [1,2,3], capital = [0,1,2]
Output:6
Explanation: All three projects can eventually be completed in capital order, summing profits 1 + 2 + 3 = 6.

⚖️Formal Constraints & Bounds

  • 1 <= k <= 105

  • 0 <= w <= 109

  • n == profits.length

  • n == capital.length

  • 1 <= n <= 105

  • 0 <= profits[i] <= 104

  • 0 <= capital[i] <= 109

Deep-Dive & Conceptual Insights

Core Insight

Because completing a project only ever increases capital w, any project affordable now stays affordable forever -- so greedily funding the most profitable currently-affordable project each round is always optimal.

Real-World Scenario & Production Applications

Venture capital fund sequencing, R&D project portfolio selection under a growing budget, and grant allocation with capital-eligibility gates.

Subproblems & Recurrence Decomposition3 Phases

🧩Subproblem 1: Capital Min-Heap -- the Waiting Room

Every project starts locked in a min-heap keyed by its required capital. This heap only ever shrinks: once a project is affordable it never re-locks, because capital w only grows.

Mathematical Recurrence / Code Invariant
min_heap = list(zip(capital, profits))
heapq.heapify(min_heap)
max_heap = []

Step-by-Step Execution Trace Table

RoundUnlocked into Max-HeapChosen ProfitNew w
1(cap=0, profit=1)10 + 1 = 1
2(cap=1, profit=2), (cap=1, profit=3)31 + 3 = 4
Code Shape
Archetype Code Shape
Python
1min_heap = heapify(list(zip(capital, profit)))
2max_heap = []
3for _ in range(k):
4 while min_heap and min_heap[0][0] <= w:
5 cap, prof = heappop(min_heap)
6 heappush(max_heap, -prof)
7 if not max_heap:
8 break
9 w += -heappop(max_heap)
10return w

Conceptual Narrative

Two heaps, but unlike the running-median pattern where they split data by VALUE, here they split candidates by ELIGIBILITY — one heap holds what you can't afford yet, the other holds what you can afford right now, ranked by payoff.

🧭 Conceptual Foundation & Pattern Intuition

A venture fund starts with capital w and may complete at most k projects, each requiring an up-front capital[i] and yielding profit[i]. Since completing a project only ever increases w (never decreases it), any project affordable today stays affordable forever after — capital never has to be "returned." This monotonicity is exactly what makes a greedy exchange argument work: among everything currently affordable, always taking the single most profitable one can never be beaten by saving it for later, because later you will have strictly more capital and the same option still available.

🏟️ The Analogy: A Startup Accelerator With a Capital Gate

Imagine an accelerator that reviews a stack of pitch decks. Some pitches require more seed capital than the accelerator currently has — those sit in a waiting room sorted by "cheapest to unlock first." Every time the accelerator's bank balance grows, it pulls every deck it can now afford out of the waiting room and drops it into a shortlist sorted by projected profit. It then always funds the single most profitable pitch in that shortlist. Because funding a pitch only adds money to the bank, nothing already unlocked ever gets re-locked — the shortlist only grows.

🔑 The Key Idea in the Code

The min-heap only ever shrinks (projects move out, never back in); the max-heap only ever grows within a round. Together they turn "greedily pick the best affordable option, k times" into O((N + k) log N).

  • Pushing all projects into profit max-heap initially: Projects can only be selected if required capital ≤\le≤ current available capital www. Pushing all projects into the max-heap ignores capital constraints.

  • Repeated full linear scan O(K⋅N)O(K \cdot N)O(K⋅N): Scanning all remaining projects every round to check affordability takes quadratic time. Sort projects by capital once and advance a single pointer.

  • Exhausting available capital prematurely: If the profit max-heap is empty before completing kkk projects (no affordable projects remain), the loop must terminate early and return current capital www.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

At most k selections + each choice has a prerequisite (capital) that only grows over time + maximize a cumulative reward.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Invariant: capital w is monotonically non-decreasing, so any project affordable now remains affordable in every future round.

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

  • Forgetting to negate profit for the max-heap (Python's heapq is min-heap only).

  • Breaking out of the round loop instead of the outer k loop when the max-heap is empty but more capital-gated projects still exist for a later round -- actually the correct break IS on max-heap empty, since no project is currently affordable and capital cannot grow without funding one.

The 60-Second Interview Pitch

Say this out loud before you type a single line

"I keep a min-heap of (capital, profit) for locked projects and a max-heap of profit for unlocked ones. Each of the k rounds, I move every project with capital <= w into the max-heap, then greedily fund the most profitable one, adding its profit to w. If nothing is unlocked, I stop early. Runs in O((N + k) log N) time and O(N) space."

Big-O Invariant Derivation

Complexity & Mathematical Proof

TIME COMPLEXITY

O((N + k) log N)

Look at the execution steps: Building the capital min-heap of N projects is O(N) via heapify. Across all k rounds, each project is unlocked (pushed into the max-heap) at most once total, and each round pops at most one project from the max-heap. Total heap operations are O(N + k), each O(log N).

SPACE COMPLEXITY

O(N) Auxiliary

Look at memory allocations: Call stack uses O(1) Iterative. The min-heap and max-heap together never hold more than N (capital, profit) pairs.

Formal Recurrence Relation

T(N,k)=O(Nlog⁡N)+O(klog⁡N)=O((N+k)log⁡N)T(N, k) = O(N \log N) + O(k \log N) = O((N + k) \log N)T(N,k)=O(NlogN)+O(klogN)=O((N+k)logN)

Derivation Progression

Capital Min-Heap Construction

O(N) heapify

All N (capital, profit) pairs are heapified once up front.

Unlock + Greedy Fund Rounds

O((N+k)log⁡N)O((N + k) \log N)O((N+k)logN)

Across all k rounds, every project is unlocked into the max-heap at most once (O(N log N) total), and each round pops at most one project (O(k log N) total).

Total Time Complexity

O((N+k)log⁡N)O((N + k) \log N)O((N+k)logN)

Dominated by the one-time unlock cost plus at most k pops.

Variable Definitions

NNN

Number of candidate projects

kkk

Maximum number of projects that can be completed

Memory Architecture & Bounds

🟣 Call Stack

O(1) Iterative

🔵 Auxiliary Heap

O(N) Min-heap and max-heap together hold at most N pairs

🟢 Output Space

O(1) Single integer capital

Boundary Best / Worst Cases

Best Case

O(Nlog⁡N)O(N \log N)O(NlogN) if k = 1.

Average Case

O((N+k)log⁡N)O((N + k) \log N)O((N+k)logN).

Worst Case

O((N+k)log⁡N)O((N + k) \log N)O((N+k)logN) when k ≥ N.

Binary Heap Priority Queue Tree

Binary Heap Priority Queue Tree
Synthesizing vector architecture diagram...
Staff+ Engineering Perspective

Senior SWE Deconstruction & Hardware Caveats

ARCHITECTURAL SIGNALS & INTERVIEW TRIGGERS

Trigger: "maximize capital after completing at most k distinct projects". Greedy selection with dynamic availability: you can only start projects where capital[i] <= w, and you want to greedily pick the one with maximum profits[i]. A Senior SWE splits the dimensions: Sort by Capital Requirement + Max-Heap of Available Profits.

CONSTRAINTS & BOUNDS

k,n≤105k, n \le 10^5k,n≤105, w≤109w \le 10^9w≤109. Time budget: O(Nlog⁡N+klog⁡N)O(N \log N + k \log N)O(NlogN+klogN), easily handling 10510^5105 operations in <100< 100<100ms.

FAANG PRODUCTION TRAPS & EDGE CASES

Stalling out early: if available_profits is empty and the next project in the sorted list requires more capital than current www, no further projects can ever be unlocked; terminate the loop early and return www.

Theory Context•Priority Queue / Heap
HardLC 502

IPO (LeetCode 502)

Target Frequency:MetaAppleAmazon

Imagine the company LeetCode wants to raise money through an IPO, and to make itself more attractive to investors it first wants to grow its capital by completing some projects. It only has the resources to complete at most k of them before the IPO. Help LeetCode pick the projects that grow its capital the most.

You're given n available projects. The i-th project pays out pure profit profits[i], but needs a minimum capital of capital[i] in hand before it can even be started.

You start with w capital, and every completed project's profit gets folded straight back into your capital, growing what you can afford to fund next.

Choose up to k distinct projects so that your final capital ends up as large as possible, and return that maximized amount.

Worked Examples

Example 1
Input:k = 2, w = 0, profits = [1,2,3], capital = [0,1,1]
Output:4
Explanation: You start with 0 capital, so project 0 (needing 0 capital) is the only one you can afford; completing it raises your capital to 1. That capital now unlocks either project 1 or project 2 -- picking the more profitable one, project 2, brings your total to 0 + 1 + 3 = 4.
Example 2
Input:k = 3, w = 0, profits = [1,2,3], capital = [0,1,2]
Output:6
Explanation: All three projects can eventually be completed in capital order, summing profits 1 + 2 + 3 = 6.

⚖️Formal Constraints & Bounds

  • 1 <= k <= 105

  • 0 <= w <= 109

  • n == profits.length

  • n == capital.length

  • 1 <= n <= 105

  • 0 <= profits[i] <= 104

  • 0 <= capital[i] <= 109

Deep-Dive & Conceptual Insights

Core Insight

Because completing a project only ever increases capital w, any project affordable now stays affordable forever -- so greedily funding the most profitable currently-affordable project each round is always optimal.

Real-World Scenario & Production Applications

Venture capital fund sequencing, R&D project portfolio selection under a growing budget, and grant allocation with capital-eligibility gates.

Subproblems & Recurrence Decomposition3 Phases

🧩Subproblem 1: Capital Min-Heap -- the Waiting Room

Every project starts locked in a min-heap keyed by its required capital. This heap only ever shrinks: once a project is affordable it never re-locks, because capital w only grows.

Mathematical Recurrence / Code Invariant
min_heap = list(zip(capital, profits))
heapq.heapify(min_heap)
max_heap = []

Step-by-Step Execution Trace Table

RoundUnlocked into Max-HeapChosen ProfitNew w
1(cap=0, profit=1)10 + 1 = 1
2(cap=1, profit=2), (cap=1, profit=3)31 + 3 = 4
Code Shape
Archetype Code Shape
Python
1min_heap = heapify(list(zip(capital, profit)))
2max_heap = []
3for _ in range(k):
4 while min_heap and min_heap[0][0] <= w:
5 cap, prof = heappop(min_heap)
6 heappush(max_heap, -prof)
7 if not max_heap:
8 break
9 w += -heappop(max_heap)
10return w

Conceptual Narrative

Two heaps, but unlike the running-median pattern where they split data by VALUE, here they split candidates by ELIGIBILITY — one heap holds what you can't afford yet, the other holds what you can afford right now, ranked by payoff.

🧭 Conceptual Foundation & Pattern Intuition

A venture fund starts with capital w and may complete at most k projects, each requiring an up-front capital[i] and yielding profit[i]. Since completing a project only ever increases w (never decreases it), any project affordable today stays affordable forever after — capital never has to be "returned." This monotonicity is exactly what makes a greedy exchange argument work: among everything currently affordable, always taking the single most profitable one can never be beaten by saving it for later, because later you will have strictly more capital and the same option still available.

🏟️ The Analogy: A Startup Accelerator With a Capital Gate

Imagine an accelerator that reviews a stack of pitch decks. Some pitches require more seed capital than the accelerator currently has — those sit in a waiting room sorted by "cheapest to unlock first." Every time the accelerator's bank balance grows, it pulls every deck it can now afford out of the waiting room and drops it into a shortlist sorted by projected profit. It then always funds the single most profitable pitch in that shortlist. Because funding a pitch only adds money to the bank, nothing already unlocked ever gets re-locked — the shortlist only grows.

🔑 The Key Idea in the Code

The min-heap only ever shrinks (projects move out, never back in); the max-heap only ever grows within a round. Together they turn "greedily pick the best affordable option, k times" into O((N + k) log N).

  • Pushing all projects into profit max-heap initially: Projects can only be selected if required capital ≤\le≤ current available capital www. Pushing all projects into the max-heap ignores capital constraints.

  • Repeated full linear scan O(K⋅N)O(K \cdot N)O(K⋅N): Scanning all remaining projects every round to check affordability takes quadratic time. Sort projects by capital once and advance a single pointer.

  • Exhausting available capital prematurely: If the profit max-heap is empty before completing kkk projects (no affordable projects remain), the loop must terminate early and return current capital www.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

At most k selections + each choice has a prerequisite (capital) that only grows over time + maximize a cumulative reward.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Invariant: capital w is monotonically non-decreasing, so any project affordable now remains affordable in every future round.

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

  • Forgetting to negate profit for the max-heap (Python's heapq is min-heap only).

  • Breaking out of the round loop instead of the outer k loop when the max-heap is empty but more capital-gated projects still exist for a later round -- actually the correct break IS on max-heap empty, since no project is currently affordable and capital cannot grow without funding one.

The 60-Second Interview Pitch

Say this out loud before you type a single line

"I keep a min-heap of (capital, profit) for locked projects and a max-heap of profit for unlocked ones. Each of the k rounds, I move every project with capital <= w into the max-heap, then greedily fund the most profitable one, adding its profit to w. If nothing is unlocked, I stop early. Runs in O((N + k) log N) time and O(N) space."

Big-O Invariant Derivation

Complexity & Mathematical Proof

TIME COMPLEXITY

O((N + k) log N)

Look at the execution steps: Building the capital min-heap of N projects is O(N) via heapify. Across all k rounds, each project is unlocked (pushed into the max-heap) at most once total, and each round pops at most one project from the max-heap. Total heap operations are O(N + k), each O(log N).

SPACE COMPLEXITY

O(N) Auxiliary

Look at memory allocations: Call stack uses O(1) Iterative. The min-heap and max-heap together never hold more than N (capital, profit) pairs.

Formal Recurrence Relation

T(N,k)=O(Nlog⁡N)+O(klog⁡N)=O((N+k)log⁡N)T(N, k) = O(N \log N) + O(k \log N) = O((N + k) \log N)T(N,k)=O(NlogN)+O(klogN)=O((N+k)logN)

Derivation Progression

Capital Min-Heap Construction

O(N) heapify

All N (capital, profit) pairs are heapified once up front.

Unlock + Greedy Fund Rounds

O((N+k)log⁡N)O((N + k) \log N)O((N+k)logN)

Across all k rounds, every project is unlocked into the max-heap at most once (O(N log N) total), and each round pops at most one project (O(k log N) total).

Total Time Complexity

O((N+k)log⁡N)O((N + k) \log N)O((N+k)logN)

Dominated by the one-time unlock cost plus at most k pops.

Variable Definitions

NNN

Number of candidate projects

kkk

Maximum number of projects that can be completed

Memory Architecture & Bounds

🟣 Call Stack

O(1) Iterative

🔵 Auxiliary Heap

O(N) Min-heap and max-heap together hold at most N pairs

🟢 Output Space

O(1) Single integer capital

Boundary Best / Worst Cases

Best Case

O(Nlog⁡N)O(N \log N)O(NlogN) if k = 1.

Average Case

O((N+k)log⁡N)O((N + k) \log N)O((N+k)logN).

Worst Case

O((N+k)log⁡N)O((N + k) \log N)O((N+k)logN) when k ≥ N.

Binary Heap Priority Queue Tree

Binary Heap Priority Queue Tree
Synthesizing vector architecture diagram...
Staff+ Engineering Perspective

Senior SWE Deconstruction & Hardware Caveats

ARCHITECTURAL SIGNALS & INTERVIEW TRIGGERS

Trigger: "maximize capital after completing at most k distinct projects". Greedy selection with dynamic availability: you can only start projects where capital[i] <= w, and you want to greedily pick the one with maximum profits[i]. A Senior SWE splits the dimensions: Sort by Capital Requirement + Max-Heap of Available Profits.

CONSTRAINTS & BOUNDS

k,n≤105k, n \le 10^5k,n≤105, w≤109w \le 10^9w≤109. Time budget: O(Nlog⁡N+klog⁡N)O(N \log N + k \log N)O(NlogN+klogN), easily handling 10510^5105 operations in <100< 100<100ms.

FAANG PRODUCTION TRAPS & EDGE CASES

Stalling out early: if available_profits is empty and the next project in the sorted list requires more capital than current www, no further projects can ever be unlocked; terminate the loop early and return www.

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