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•Two Pointers & Sliding Window
MediumLC 11

Container With Most Water (LeetCode 11)

Target Frequency:MetaAmazonGoogleApple

You're given an integer array height of length n. Imagine n vertical lines, where the i^th line runs from (i, 0) up to (i, height[i]).

Pick any two of these lines: together with the x-axis, they mark out a container. Find the pair that holds the most water.

Return the largest amount of water any such container can hold.

Notice the container's sides can't be slanted — you're choosing two of the existing vertical lines as-is.

Code / Blueprint
8 | | |
7 | | | |
6 | | | | |
5 | | | | | |
4 | | | | | | |
3 | | | | | | | |
2 | | | | | | | | |
1 | | | | | | | | | |
0 +-+--+---+---+---+---+---+---+---+---+
0 1 2 3 4 5 6 7 8 (index)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~^
L=1 (h=8) R=8 (h=7)
<-------- Width = 7 -------->
Water Level = min(8, 7) = 7
Max Area = 7 × 7 = 49 (Optimal Reservoir)
 

Worked Examples

Example 1
Input:height = [1,8,6,2,5,4,8,3,7]
Output:49
Geometric Container & Water ReservoirVisualizing Vertical Lines, Water Containment & Bottleneck Boundary
Max Capacity: 49Optimal
2468Area = 491081left=162235445863778right=8
📐Capacity Formula

Area = width × min(h[L], h[R])
Here: 7 × 7 = 49

Bottleneck Wall

Water level is capped at 7 by the shorter line (right wall [idx 8]). Water filled higher will spill over!

Two-Pointer Decision

Always advance the shorter wall inward. Moving the taller wall only decreases width while keeping the same cap. Only moving the shorter wall can raise the bottleneck!

💡 Try it:Click any two vertical bars above to test different container pairs and see why the optimal pair produces maximum capacity!
108162235445863778leftright
Explanation: The vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. The container with maximum water is formed between line at index 1 (height 8) and line at index 8 (height 7). Water level is bounded by the shorter line (min(8, 7) = 7) and width is 8 - 1 = 7, giving max area = 7 × 7 = 49.
Example 2
Input:height = [1,1]
Output:1
Geometric Container & Water ReservoirVisualizing Vertical Lines, Water Containment & Bottleneck Boundary
Max Capacity: 1Optimal
2468Area = 110left=011right=1
📐Capacity Formula

Area = width × min(h[L], h[R])
Here: 1 × 1 = 1

Bottleneck Wall

Water level is capped at 1 by the shorter line (both walls tied). Water filled higher will spill over!

Two-Pointer Decision

Always advance the shorter wall inward. Moving the taller wall only decreases width while keeping the same cap. Only moving the shorter wall can raise the bottleneck!

💡 Try it:Click any two vertical bars above to test different container pairs and see why the optimal pair produces maximum capacity!
Explanation: Width is 1 - 0 = 1, min height is min(1, 1) = 1. Area = 1 × 1 = 1.

⚖️Formal Constraints & Bounds

  • n == height.length

  • 2 <= n <= 105

  • 0 <= height[i] <= 104

Deep-Dive & Conceptual Insights

Core Insight

The shorter line strictly bounds height and cannot produce a larger area with any narrower width, proving greedy elimination correctness.

Real-World Scenario & Production Applications

Fluid dynamics capacity calculation, structural engineering truss bounding, and stock market volatility channel containment.

Subproblems & Recurrence Decomposition3 Phases

🧩Subproblem 1: Maximal Width Baseline

Place pointers at extreme boundaries left = 0, right = len(height) - 1 to capture the widest possible container width right - left.

Mathematical Recurrence / Code Invariant
left = 0
right = len(height) - 1
max_area = 0

Step-by-Step Execution Trace Table

Stepleft (h)right (h)widthmin_hareaAction
10 (1)8 (7)818h[0]=1 < h[8]=7 → left++
21 (8)8 (7)7749h[1]=8 > h[8]=7 → right--
31 (8)7 (3)6318h[1]=8 > h[7]=3 → right--
Code Shape
Archetype Code Shape
Python
1left, right = 0, len(height) - 1
2max_area = 0
3while left < right:
4 h = min(height[left], height[right])
5 max_area = max(max_area, (right - left) * h)
6 if height[left] < height[right]:
7 left += 1
8 else:
9 right -= 1
10return max_area

Conceptual Narrative

🧭 Conceptual Foundation & Pattern Intuition

Discarding the shorter wall on purpose, when it feels like the taller one is "winning," is the single hardest leap in this pattern to trust without a proof.

🪣 The Analogy: Water Always Spills at the Shorter Wall

Picture two walls holding back water — one tall, one short. No matter how tall the taller wall is, the water can never rise above the shorter wall; it spills over the low side first. So the shorter wall is the true bottleneck on the container's capacity, not the taller one.

Now ask: if you keep the current pair and only move one pointer inward, which move could possibly do better? Moving the taller wall's pointer inward shrinks the width while the height is still capped by the (unmoved) shorter wall — area can only shrink or tie. Moving the shorter wall's pointer inward also shrinks the width, but it's the only move that has a chance of finding a taller wall to raise the bottleneck height — the only move that could ever produce a bigger area.

🔑 The Key Idea in the Code

Discarding the shorter wall's current position is safe because every other pairing that keeps that same short wall is strictly worse (smaller width, same height cap) — so nothing is ever lost by moving on.

  • Moving the taller line: Area is bounded by min(h[left], h[right]) * (right - left). Moving the taller wall only decreases width without any possibility of increasing height. You must always move the SHORTER wall.

  • Using right - left + 1 for width: Width between index left and right is right - left, NOT right - left + 1. Using +1 produces incorrect area for all containers.

  • Arbitrary tie-breaking: When height[left] == height[right], moving either pointer (or both) is mathematically safe because neither can form a larger container with any intermediate wall.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

2D area optimization bounded by two boundary endpoints.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Invariant: no container with the current shorter boundary at smaller widths can exceed the current area.

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

This problem's traps are in Common Pitfalls above.

The 60-Second Interview Pitch

Say this out loud before you type a single line

"I place pointers at 0 and len(height)-1. I compute width * min(h[left], h[right]) and record max area. Then I eliminate whichever pointer has the smaller height. Runs in O(N) time and O(1) space."

Big-O Invariant Derivation

Complexity & Mathematical Proof

TIME COMPLEXITY

O(N)

Look at the execution steps: Left and right pointers start at boundaries. Area is width * min(heights). The pointer with shorter height is moved inward because keeping it could never yield a larger area with a smaller width.

SPACE COMPLEXITY

O(1) Auxiliary

Look at memory allocations: Call stack uses O(1) Iterative. Only tracks left and right indices and max_area integer in O(1) space.

Formal Recurrence Relation

T(N) = N-1 width contractions = O(N)

Derivation Progression

Area Calculation

Area = (R - L) · min(H[L], H[R])

Computes current bounding box capacity in O(1) time.

Shorter Line Elimination

if H[L] < H[R]: L += 1 else R -= 1

The shorter line cannot form a larger container with any other remaining inner line, so it is discarded safely.

Strict Interval Shrinking

N-1 steps

Pointers meet after exactly N-1 iterations.

Variable Definitions

NNN

Total number of vertical lines in the array

Memory Architecture & Bounds

🟣 Call Stack

O(1) Iterative

🔵 Auxiliary Heap

O(1) 3 scalar registers

🟢 Output Space

O(1) Maximum water integer

Boundary Best / Worst Cases

Best Case

O(N)O(N)O(N)

Average Case

O(N)O(N)O(N)

Worst Case

O(N)O(N)O(N)

Pointer Invariant Transition Progression

Pointer Invariant Transition Progression
Synthesizing vector architecture diagram...
Staff+ Engineering Perspective

Senior SWE Deconstruction & Hardware Caveats

ARCHITECTURAL SIGNALS & INTERVIEW TRIGGERS

Triggers: "two lines together with x-axis forms container", "maximize water container can contain". Bilateral boundary convergence with greedy bottleneck elimination.

CONSTRAINTS & BOUNDS

2≤N≤1052 \le N \le 10^52≤N≤105. Naive pair checking is O(N2)O(N^2)O(N2) (TLE). Requires strictly O(N)O(N)O(N) linear time and O(1)O(1)O(1) space.

FAANG PRODUCTION TRAPS & EDGE CASES

Moving both pointers simultaneously when heights are equal: moving either is safe since the limiting height is already bounded by both lines.

Theory Context•Two Pointers & Sliding Window
MediumLC 11

Container With Most Water (LeetCode 11)

Target Frequency:MetaAmazonGoogleApple

You're given an integer array height of length n. Imagine n vertical lines, where the i^th line runs from (i, 0) up to (i, height[i]).

Pick any two of these lines: together with the x-axis, they mark out a container. Find the pair that holds the most water.

Return the largest amount of water any such container can hold.

Notice the container's sides can't be slanted — you're choosing two of the existing vertical lines as-is.

Code / Blueprint
8 | | |
7 | | | |
6 | | | | |
5 | | | | | |
4 | | | | | | |
3 | | | | | | | |
2 | | | | | | | | |
1 | | | | | | | | | |
0 +-+--+---+---+---+---+---+---+---+---+
0 1 2 3 4 5 6 7 8 (index)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~^
L=1 (h=8) R=8 (h=7)
<-------- Width = 7 -------->
Water Level = min(8, 7) = 7
Max Area = 7 × 7 = 49 (Optimal Reservoir)
 

Worked Examples

Example 1
Input:height = [1,8,6,2,5,4,8,3,7]
Output:49
Geometric Container & Water ReservoirVisualizing Vertical Lines, Water Containment & Bottleneck Boundary
Max Capacity: 49Optimal
2468Area = 491081left=162235445863778right=8
📐Capacity Formula

Area = width × min(h[L], h[R])
Here: 7 × 7 = 49

Bottleneck Wall

Water level is capped at 7 by the shorter line (right wall [idx 8]). Water filled higher will spill over!

Two-Pointer Decision

Always advance the shorter wall inward. Moving the taller wall only decreases width while keeping the same cap. Only moving the shorter wall can raise the bottleneck!

💡 Try it:Click any two vertical bars above to test different container pairs and see why the optimal pair produces maximum capacity!
108162235445863778leftright
Explanation: The vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. The container with maximum water is formed between line at index 1 (height 8) and line at index 8 (height 7). Water level is bounded by the shorter line (min(8, 7) = 7) and width is 8 - 1 = 7, giving max area = 7 × 7 = 49.
Example 2
Input:height = [1,1]
Output:1
Geometric Container & Water ReservoirVisualizing Vertical Lines, Water Containment & Bottleneck Boundary
Max Capacity: 1Optimal
2468Area = 110left=011right=1
📐Capacity Formula

Area = width × min(h[L], h[R])
Here: 1 × 1 = 1

Bottleneck Wall

Water level is capped at 1 by the shorter line (both walls tied). Water filled higher will spill over!

Two-Pointer Decision

Always advance the shorter wall inward. Moving the taller wall only decreases width while keeping the same cap. Only moving the shorter wall can raise the bottleneck!

💡 Try it:Click any two vertical bars above to test different container pairs and see why the optimal pair produces maximum capacity!
Explanation: Width is 1 - 0 = 1, min height is min(1, 1) = 1. Area = 1 × 1 = 1.

⚖️Formal Constraints & Bounds

  • n == height.length

  • 2 <= n <= 105

  • 0 <= height[i] <= 104

Deep-Dive & Conceptual Insights

Core Insight

The shorter line strictly bounds height and cannot produce a larger area with any narrower width, proving greedy elimination correctness.

Real-World Scenario & Production Applications

Fluid dynamics capacity calculation, structural engineering truss bounding, and stock market volatility channel containment.

Subproblems & Recurrence Decomposition3 Phases

🧩Subproblem 1: Maximal Width Baseline

Place pointers at extreme boundaries left = 0, right = len(height) - 1 to capture the widest possible container width right - left.

Mathematical Recurrence / Code Invariant
left = 0
right = len(height) - 1
max_area = 0

Step-by-Step Execution Trace Table

Stepleft (h)right (h)widthmin_hareaAction
10 (1)8 (7)818h[0]=1 < h[8]=7 → left++
21 (8)8 (7)7749h[1]=8 > h[8]=7 → right--
31 (8)7 (3)6318h[1]=8 > h[7]=3 → right--
Code Shape
Archetype Code Shape
Python
1left, right = 0, len(height) - 1
2max_area = 0
3while left < right:
4 h = min(height[left], height[right])
5 max_area = max(max_area, (right - left) * h)
6 if height[left] < height[right]:
7 left += 1
8 else:
9 right -= 1
10return max_area

Conceptual Narrative

🧭 Conceptual Foundation & Pattern Intuition

Discarding the shorter wall on purpose, when it feels like the taller one is "winning," is the single hardest leap in this pattern to trust without a proof.

🪣 The Analogy: Water Always Spills at the Shorter Wall

Picture two walls holding back water — one tall, one short. No matter how tall the taller wall is, the water can never rise above the shorter wall; it spills over the low side first. So the shorter wall is the true bottleneck on the container's capacity, not the taller one.

Now ask: if you keep the current pair and only move one pointer inward, which move could possibly do better? Moving the taller wall's pointer inward shrinks the width while the height is still capped by the (unmoved) shorter wall — area can only shrink or tie. Moving the shorter wall's pointer inward also shrinks the width, but it's the only move that has a chance of finding a taller wall to raise the bottleneck height — the only move that could ever produce a bigger area.

🔑 The Key Idea in the Code

Discarding the shorter wall's current position is safe because every other pairing that keeps that same short wall is strictly worse (smaller width, same height cap) — so nothing is ever lost by moving on.

  • Moving the taller line: Area is bounded by min(h[left], h[right]) * (right - left). Moving the taller wall only decreases width without any possibility of increasing height. You must always move the SHORTER wall.

  • Using right - left + 1 for width: Width between index left and right is right - left, NOT right - left + 1. Using +1 produces incorrect area for all containers.

  • Arbitrary tie-breaking: When height[left] == height[right], moving either pointer (or both) is mathematically safe because neither can form a larger container with any intermediate wall.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

2D area optimization bounded by two boundary endpoints.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Invariant: no container with the current shorter boundary at smaller widths can exceed the current area.

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

This problem's traps are in Common Pitfalls above.

The 60-Second Interview Pitch

Say this out loud before you type a single line

"I place pointers at 0 and len(height)-1. I compute width * min(h[left], h[right]) and record max area. Then I eliminate whichever pointer has the smaller height. Runs in O(N) time and O(1) space."

Big-O Invariant Derivation

Complexity & Mathematical Proof

TIME COMPLEXITY

O(N)

Look at the execution steps: Left and right pointers start at boundaries. Area is width * min(heights). The pointer with shorter height is moved inward because keeping it could never yield a larger area with a smaller width.

SPACE COMPLEXITY

O(1) Auxiliary

Look at memory allocations: Call stack uses O(1) Iterative. Only tracks left and right indices and max_area integer in O(1) space.

Formal Recurrence Relation

T(N) = N-1 width contractions = O(N)

Derivation Progression

Area Calculation

Area = (R - L) · min(H[L], H[R])

Computes current bounding box capacity in O(1) time.

Shorter Line Elimination

if H[L] < H[R]: L += 1 else R -= 1

The shorter line cannot form a larger container with any other remaining inner line, so it is discarded safely.

Strict Interval Shrinking

N-1 steps

Pointers meet after exactly N-1 iterations.

Variable Definitions

NNN

Total number of vertical lines in the array

Memory Architecture & Bounds

🟣 Call Stack

O(1) Iterative

🔵 Auxiliary Heap

O(1) 3 scalar registers

🟢 Output Space

O(1) Maximum water integer

Boundary Best / Worst Cases

Best Case

O(N)O(N)O(N)

Average Case

O(N)O(N)O(N)

Worst Case

O(N)O(N)O(N)

Pointer Invariant Transition Progression

Pointer Invariant Transition Progression
Synthesizing vector architecture diagram...
Staff+ Engineering Perspective

Senior SWE Deconstruction & Hardware Caveats

ARCHITECTURAL SIGNALS & INTERVIEW TRIGGERS

Triggers: "two lines together with x-axis forms container", "maximize water container can contain". Bilateral boundary convergence with greedy bottleneck elimination.

CONSTRAINTS & BOUNDS

2≤N≤1052 \le N \le 10^52≤N≤105. Naive pair checking is O(N2)O(N^2)O(N2) (TLE). Requires strictly O(N)O(N)O(N) linear time and O(1)O(1)O(1) space.

FAANG PRODUCTION TRAPS & EDGE CASES

Moving both pointers simultaneously when heights are equal: moving either is safe since the limiting height is already bounded by both lines.

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