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 15

3Sum (LeetCode 15)

Target Frequency:MetaAmazonGoogleApple

You have an integer array nums. Find every triplet of three distinct positions i, j, k whose values nums[i] + nums[j] + nums[k] sum to zero, and return those triplets of values.

The output must not contain the same triplet of values more than once.

Worked Examples

Example 1
Input:nums = [-1,0,1,2,-1,-4]
Output:[[-1,-1,2],[-1,0,1]]
Explanation: Distinct valid triplets summing to 0 are [-1,-1,2] and [-1,0,1].
Example 2
Input:nums = [0,1,1]
Output:[]
Explanation: No triplet sums to 0.
Example 3
Input:nums = [0,0,0]
Output:[[0,0,0]]
Explanation: Only triplet is [0,0,0].

⚖️Formal Constraints & Bounds

  • 3 <= nums.length <= 3000

  • -105 <= nums[i] <= 105

Deep-Dive & Conceptual Insights

Core Insight

Backward comparison nums[i] == nums[i-1] prevents skipping legitimate duplicate values within the first valid triplet, while eliminating duplicate triplet evaluations.

Real-World Scenario & Production Applications

Financial portfolio 3-asset arbitrage balancing, chemical compound balance equations, and zero-sum game equilibrium finding.

Subproblems & Recurrence Decomposition3 Phases

🧩Subproblem 1: Array Sorting & Anchor Fixing

Sort nums in O(N log N) to create monotonic order. Loop anchor i from 0 to N-3, pruning if nums[i] > 0 and skipping duplicate anchors with i > 0 and nums[i] == nums[i - 1].

Mathematical Recurrence / Code Invariant
nums.sort()
for i in range(len(nums) - 2):
    if nums[i] > 0: break
    if i > 0 and nums[i] == nums[i - 1]: continue

Step-by-Step Execution Trace Table

Stepi (anchor)leftrightsumAction
10 (-4)1 (-1)5 (2)-3sum < 0 → left++
21 (-1)2 (-1)5 (2)0Match [-1,-1,2]! Skip dups → left++, right--
31 (-1)3 (0)4 (1)0Match [-1,0,1]! Skip dups → left++, right--
Code Shape
Archetype Code Shape
Python
1nums.sort()
2res = []
3for i in range(len(nums) - 2):
4 if nums[i] > 0:
5 break
6 if i > 0 and nums[i] == nums[i - 1]:
7 continue
8 left, right = i + 1, len(nums) - 1
9 while left < right:
10 total = nums[i] + nums[left] + nums[right]
11 if total < 0:
12 left += 1
13 elif total > 0:
14 right -= 1
15 else:
16 res.append([nums[i], nums[left], nums[right]])
17 left += 1
18 right -= 1
19return res

Conceptual Narrative

🧭 Conceptual Foundation & Pattern Intuition

3Sum wants every distinct-position triplet from nums whose three values add to zero. Checking every triplet directly costs O(N3)O(N^3)O(N3) time, and de-duplicating the results with a hash set burns a lot of memory. Sorting the array first in O(Nlog⁡N)O(N \log N)O(NlogN) changes the shape of the problem: pin one element nums[i] as an anchor, and what's left is just Two Sum II over the sorted suffix nums[i+1..n-1].

🏟️ The Analogy: The Three-Person Committee

Imagine selecting a 3-person committee from a line of candidates arranged strictly by height. First, you appoint candidate AAA. Then, you send two scouts to the remaining line—one starting at the shortest end and one at the tallest end—to find two candidates whose heights balance candidate AAA's weight. If the next candidate in line has the exact same height as candidate AAA, appointing them would produce an identical committee, so you skip them immediately.

🔑 Why It Works

The secret to zero duplicate sets lies in two-tier duplicate suppression:

  1. Outer loop skips if nums[i] == nums[i-1].
  2. Inner loop skips consecutive identical values after recording a match.
  • Duplicate triplets from anchor element: Forgetting if i > 0 and nums[i] == nums[i - 1]: continue generates duplicate triplets for identical anchor values.

  • Duplicate triplets from inner pointers: After recording a valid triplet [nums[i], nums[left], nums[right]], you must advance both pointers past all identical elements (while left < right and nums[left] == nums[left + 1]: left += 1).

  • Missing sort step: 3Sum relies strictly on two-pointer convergence. Forgetting nums.sort() produces completely incorrect results in O(N^3) time.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

Finding all unique triplets that sum to a target value.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Invariant: array is sorted, anchor i is unique, and inner pointers skip identical adjacent values after recording.

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

  • Checking forward duplicates: nums[i] == nums[i + 1] skips valid triplets with repeated elements like [-1, -1, 2].

  • Skipping inner duplicates before recording: always record the match first, then slide past duplicates.

The 60-Second Interview Pitch

Say this out loud before you type a single line

"I sort the array in O(N log N). I iterate an anchor i from 0 to N-3, skipping duplicates where nums[i] == nums[i-1]. Inside, I run converging two pointers on [i+1..n-1]. When the sum is 0, I record the triplet and advance past identical values. Total time is O(N^2) and O(1) auxiliary space."

Big-O Invariant Derivation

Complexity & Mathematical Proof

TIME COMPLEXITY

O(N^2)

Sorting takes O(N log N). The outer loop runs N times, and the inner converging two-pointer scan takes O(N) steps across the remaining suffix, giving O(N log N + N * N) = O(N^2) overall.

SPACE COMPLEXITY

O(1) Auxiliary

Apart from the returned output list and O(log N) sorting call stack, only integer pointers (i, left, right) and sum accumulators are maintained in O(1) auxiliary space.

Formal Recurrence Relation

T(N)=O(Nlog⁡N)+∑i=0N−3(N−i)=O(N2)T(N) = O(N \log N) + \sum_{i=0}^{N-3} (N - i) = O(N^2)T(N)=O(NlogN)+∑i=0N−3​(N−i)=O(N2)

Derivation Progression

Sorting

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

Orders elements monotonically to enable directional two-pointer decisions.

Anchor Iteration & Inner Two Pointers

∑i=0N−3O(N−i)=O(N2)\sum_{i=0}^{N-3} O(N - i) = O(N^2)∑i=0N−3​O(N−i)=O(N2)

Each fixed anchor performs a linear inward scan of the remaining array.

Variable Definitions

NNN

Number of elements in nums

Memory Architecture & Bounds

🟣 Call Stack

O(log N) for in-place sort

🔵 Auxiliary Heap

O(1) 3 scalar registers

🟢 Output Space

O(N^2) for unique triplets list

Boundary Best / Worst Cases

Best Case

O(N2)O(N^2)O(N2) (or O(N)O(N)O(N) if earliest anchor > 0 breaks immediately).

Average Case

O(N2)O(N^2)O(N2).

Worst Case

O(N2)O(N^2)O(N2) full scan.

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: "three elements sum to zero", "solution set must not contain duplicate triplets". Dimensionality reduction (3Sum→2Sum3\text{Sum} \to 2\text{Sum}3Sum→2Sum) by fixing the first element and executing converging Two-Pointers on the sorted suffix.

CONSTRAINTS & BOUNDS

3≤N≤30003 \le N \le 30003≤N≤3000. O(N2)O(N^2)O(N2) time budget (30002≈9×1063000^2 \approx 9 \times 10^630002≈9×106 operations, comfortably <100< 100<100ms).

FAANG PRODUCTION TRAPS & EDGE CASES

Early exit optimization: if nums[i] > 0, break immediately (three positive numbers can never sum to zero).

Theory Context•Two Pointers & Sliding Window
MediumLC 15

3Sum (LeetCode 15)

Target Frequency:MetaAmazonGoogleApple

You have an integer array nums. Find every triplet of three distinct positions i, j, k whose values nums[i] + nums[j] + nums[k] sum to zero, and return those triplets of values.

The output must not contain the same triplet of values more than once.

Worked Examples

Example 1
Input:nums = [-1,0,1,2,-1,-4]
Output:[[-1,-1,2],[-1,0,1]]
Explanation: Distinct valid triplets summing to 0 are [-1,-1,2] and [-1,0,1].
Example 2
Input:nums = [0,1,1]
Output:[]
Explanation: No triplet sums to 0.
Example 3
Input:nums = [0,0,0]
Output:[[0,0,0]]
Explanation: Only triplet is [0,0,0].

⚖️Formal Constraints & Bounds

  • 3 <= nums.length <= 3000

  • -105 <= nums[i] <= 105

Deep-Dive & Conceptual Insights

Core Insight

Backward comparison nums[i] == nums[i-1] prevents skipping legitimate duplicate values within the first valid triplet, while eliminating duplicate triplet evaluations.

Real-World Scenario & Production Applications

Financial portfolio 3-asset arbitrage balancing, chemical compound balance equations, and zero-sum game equilibrium finding.

Subproblems & Recurrence Decomposition3 Phases

🧩Subproblem 1: Array Sorting & Anchor Fixing

Sort nums in O(N log N) to create monotonic order. Loop anchor i from 0 to N-3, pruning if nums[i] > 0 and skipping duplicate anchors with i > 0 and nums[i] == nums[i - 1].

Mathematical Recurrence / Code Invariant
nums.sort()
for i in range(len(nums) - 2):
    if nums[i] > 0: break
    if i > 0 and nums[i] == nums[i - 1]: continue

Step-by-Step Execution Trace Table

Stepi (anchor)leftrightsumAction
10 (-4)1 (-1)5 (2)-3sum < 0 → left++
21 (-1)2 (-1)5 (2)0Match [-1,-1,2]! Skip dups → left++, right--
31 (-1)3 (0)4 (1)0Match [-1,0,1]! Skip dups → left++, right--
Code Shape
Archetype Code Shape
Python
1nums.sort()
2res = []
3for i in range(len(nums) - 2):
4 if nums[i] > 0:
5 break
6 if i > 0 and nums[i] == nums[i - 1]:
7 continue
8 left, right = i + 1, len(nums) - 1
9 while left < right:
10 total = nums[i] + nums[left] + nums[right]
11 if total < 0:
12 left += 1
13 elif total > 0:
14 right -= 1
15 else:
16 res.append([nums[i], nums[left], nums[right]])
17 left += 1
18 right -= 1
19return res

Conceptual Narrative

🧭 Conceptual Foundation & Pattern Intuition

3Sum wants every distinct-position triplet from nums whose three values add to zero. Checking every triplet directly costs O(N3)O(N^3)O(N3) time, and de-duplicating the results with a hash set burns a lot of memory. Sorting the array first in O(Nlog⁡N)O(N \log N)O(NlogN) changes the shape of the problem: pin one element nums[i] as an anchor, and what's left is just Two Sum II over the sorted suffix nums[i+1..n-1].

🏟️ The Analogy: The Three-Person Committee

Imagine selecting a 3-person committee from a line of candidates arranged strictly by height. First, you appoint candidate AAA. Then, you send two scouts to the remaining line—one starting at the shortest end and one at the tallest end—to find two candidates whose heights balance candidate AAA's weight. If the next candidate in line has the exact same height as candidate AAA, appointing them would produce an identical committee, so you skip them immediately.

🔑 Why It Works

The secret to zero duplicate sets lies in two-tier duplicate suppression:

  1. Outer loop skips if nums[i] == nums[i-1].
  2. Inner loop skips consecutive identical values after recording a match.
  • Duplicate triplets from anchor element: Forgetting if i > 0 and nums[i] == nums[i - 1]: continue generates duplicate triplets for identical anchor values.

  • Duplicate triplets from inner pointers: After recording a valid triplet [nums[i], nums[left], nums[right]], you must advance both pointers past all identical elements (while left < right and nums[left] == nums[left + 1]: left += 1).

  • Missing sort step: 3Sum relies strictly on two-pointer convergence. Forgetting nums.sort() produces completely incorrect results in O(N^3) time.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

Finding all unique triplets that sum to a target value.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Invariant: array is sorted, anchor i is unique, and inner pointers skip identical adjacent values after recording.

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

  • Checking forward duplicates: nums[i] == nums[i + 1] skips valid triplets with repeated elements like [-1, -1, 2].

  • Skipping inner duplicates before recording: always record the match first, then slide past duplicates.

The 60-Second Interview Pitch

Say this out loud before you type a single line

"I sort the array in O(N log N). I iterate an anchor i from 0 to N-3, skipping duplicates where nums[i] == nums[i-1]. Inside, I run converging two pointers on [i+1..n-1]. When the sum is 0, I record the triplet and advance past identical values. Total time is O(N^2) and O(1) auxiliary space."

Big-O Invariant Derivation

Complexity & Mathematical Proof

TIME COMPLEXITY

O(N^2)

Sorting takes O(N log N). The outer loop runs N times, and the inner converging two-pointer scan takes O(N) steps across the remaining suffix, giving O(N log N + N * N) = O(N^2) overall.

SPACE COMPLEXITY

O(1) Auxiliary

Apart from the returned output list and O(log N) sorting call stack, only integer pointers (i, left, right) and sum accumulators are maintained in O(1) auxiliary space.

Formal Recurrence Relation

T(N)=O(Nlog⁡N)+∑i=0N−3(N−i)=O(N2)T(N) = O(N \log N) + \sum_{i=0}^{N-3} (N - i) = O(N^2)T(N)=O(NlogN)+∑i=0N−3​(N−i)=O(N2)

Derivation Progression

Sorting

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

Orders elements monotonically to enable directional two-pointer decisions.

Anchor Iteration & Inner Two Pointers

∑i=0N−3O(N−i)=O(N2)\sum_{i=0}^{N-3} O(N - i) = O(N^2)∑i=0N−3​O(N−i)=O(N2)

Each fixed anchor performs a linear inward scan of the remaining array.

Variable Definitions

NNN

Number of elements in nums

Memory Architecture & Bounds

🟣 Call Stack

O(log N) for in-place sort

🔵 Auxiliary Heap

O(1) 3 scalar registers

🟢 Output Space

O(N^2) for unique triplets list

Boundary Best / Worst Cases

Best Case

O(N2)O(N^2)O(N2) (or O(N)O(N)O(N) if earliest anchor > 0 breaks immediately).

Average Case

O(N2)O(N^2)O(N2).

Worst Case

O(N2)O(N^2)O(N2) full scan.

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: "three elements sum to zero", "solution set must not contain duplicate triplets". Dimensionality reduction (3Sum→2Sum3\text{Sum} \to 2\text{Sum}3Sum→2Sum) by fixing the first element and executing converging Two-Pointers on the sorted suffix.

CONSTRAINTS & BOUNDS

3≤N≤30003 \le N \le 30003≤N≤3000. O(N2)O(N^2)O(N2) time budget (30002≈9×1063000^2 \approx 9 \times 10^630002≈9×106 operations, comfortably <100< 100<100ms).

FAANG PRODUCTION TRAPS & EDGE CASES

Early exit optimization: if nums[i] > 0, break immediately (three positive numbers can never sum to zero).

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