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
EasyLC 283

Move Zeroes (LeetCode 283)

Target Frequency:MetaAppleAmazon

You're given an integer array nums. Push every 0 toward the end of the array, but keep the non-zero values in their original relative order.

Note that this has to happen in-place — no copying into a second array.

Worked Examples

Example 1
Input:nums = [0,1,0,3,12]
Output:[1,3,12,0,0]
Explanation: All zeroes are relocated to the end while maintaining the relative order of non-zero elements [1, 3, 12].
Example 2
Input:nums = [0]
Output:[0]
Explanation: A single-element array containing zero remains unchanged.

⚖️Formal Constraints & Bounds

  • 1 <= nums.length <= 104

  • -231 <= nums[i] <= 231 - 1

Deep-Dive & Conceptual Insights

Core Insight

Separating discovery of non-zeroes from zero-filling avoids expensive O(N^2) element shifting.

Real-World Scenario & Production Applications

Sparse array compaction, memory garbage collection compaction phases, and streaming event buffer filtering.

Subproblems & Recurrence Decomposition3 Phases

🧩Subproblem 1: Non-Zero Write Pointer Setup

insert_pos tracks where the next non-zero value should be written, starting at index 0.

Mathematical Recurrence / Code Invariant
insert_pos = 0

Step-by-Step Execution Trace Table

Stepreadernums[reader]Actionnums Statewriter
1000 == 0 → skip[0, 1, 0, 3, 12]0
2111 != 0 → nums[0]=1, writer++[1, 1, 0, 3, 12]1
3200 == 0 → skip[1, 1, 0, 3, 12]1
4333 != 0 → nums[1]=3, writer++[1, 3, 0, 3, 12]2
541212 != 0 → nums[2]=12, writer++[1, 3, 12, 3, 12]3
Fill3..4—Zero-fill from writer=3 to end[1, 3, 12, 0, 0]3
Code Shape
Archetype Code Shape
Python
1writer = 0
2for reader in range(len(nums)):
3 if nums[reader] != 0:
4 nums[writer] = nums[reader]
5 writer += 1
6for i in range(writer, len(nums)):
7 nums[i] = 0
8return nums

Conceptual Narrative

🧭 Conceptual Foundation & Pattern Intuition

Moving zeroes to the end of an array while maintaining the relative order of non-zero elements is the canonical Slow/Fast Reader-Writer Partitioning pattern. Rather than shifting elements backward upon discovering a zero (O(N2)O(N^2)O(N2) time), we decouple the role of scanning elements from the role of writing validated data. The writer pointer w maintains the frontier of clean non-zero elements, while the reader pointer r traverses ahead to inspect candidates.

🏟️ The Analogy: The Snowplow on a Highway

Imagine a snowplow (r) driving down a multi-lane highway covered in snowdrifts (0s) and stranded cars (non-zero numbers). Behind the plow follows a tow truck (w). Whenever the plow finds a working car, it radios the tow truck, which parks it at the earliest open lane slot (w). Once the highway has been inspected, all working cars are packed neatly at the beginning of the road; the rest of the highway behind them is simply paved over with asphalt (0s).

🔑 Why It Works

By swapping nums[w] and nums[r] instead of performing a two-pass overwrite, the algorithm automatically moves zeros backward without requiring a second zero-fill loop! When w == r, the element swaps with itself (a no-op). When zeroes have been encountered, w lags behind r, pointing precisely to the leftmost zero waiting to receive the next non-zero car.

  • Overwriting non-zero values with zero prematurely: When using separate read and write pointers, writing nums[writer] = 0 during the initial compaction pass will overwrite unprocessed non-zero values ahead of it. Only fill remaining slots with zeros after the reader pass finishes.

  • Redundant self-assignment when no zeros have been encountered: If all initial elements are non-zero, reader == writer. Writing nums[writer] = nums[reader] or swapping on every step does redundant memory writes. Guard with if reader != writer:.

  • Incomplete zero-fill at array tail: After moving all non-zero elements to [0..writer-1], forgetting the second pass while writer < len(nums): nums[writer] = 0; writer += 1 leaves stale duplicate values at the tail.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

In-place array filtering + relative ordering preservation + constant space requirement.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Invariant: nums[0..writer-1] contains all non-zero elements encountered so far in relative order.

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

  • Using expensive nested array deletion / splice operations: O(N^2) trap.

The 60-Second Interview Pitch

Say this out loud before you type a single line

"I iterate with a reader pointer. When nums[reader] is non-zero, I write it to nums[writer] and increment writer. After the loop, I fill indices from writer to the end with zeroes. 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: Fast pointer scans array; on non-zero, swaps with slow pointer or writes to slow pointer index and advances. Single linear pass.

SPACE COMPLEXITY

O(1) Auxiliary

Look at memory allocations: Call stack uses O(1) Iterative. Modifies array in-place with two scalar pointer indices.

Formal Recurrence Relation

T(N) = O(N)

Derivation Progression

Single Scan Pass

for r ∈ [0, N-1]

Right pointer traverses the array from 0 to N-1.

In-Place Swap

nums[l], nums[r] = nums[r], nums[l]

Maintains invariant that nums[0..l-1] contains non-zero elements in original order.

Total Work

N iterations × O(1) = O(N)

Every element is inspected once and swapped at most once.

Variable Definitions

NNN

Total number of elements in the array

Memory Architecture & Bounds

🟣 Call Stack

O(1) Iterative

🔵 Auxiliary Heap

O(1) Two scalar pointers

🟢 Output Space

O(1) In-place array modification

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: "move all 0's to the end", "maintain relative order of non-zero elements", "in-place without copying the array". Compaction and snowplow pattern: all non-zero elements must be compacted into the prefix, leaving zeros trailing.

CONSTRAINTS & BOUNDS

1≤N≤1041 \le N \le 10^41≤N≤104. Time budget O(N)O(N)O(N) single pass, auxiliary space O(1)O(1)O(1).

FAANG PRODUCTION TRAPS & EDGE CASES

Overwriting elements instead of swapping (which requires a second loop to fill zeros). When array has no zeros, slow == fast; swapping nums[slow], nums[fast] is an identity operation that safely preserves order.

Theory Context•Two Pointers & Sliding Window
EasyLC 283

Move Zeroes (LeetCode 283)

Target Frequency:MetaAppleAmazon

You're given an integer array nums. Push every 0 toward the end of the array, but keep the non-zero values in their original relative order.

Note that this has to happen in-place — no copying into a second array.

Worked Examples

Example 1
Input:nums = [0,1,0,3,12]
Output:[1,3,12,0,0]
Explanation: All zeroes are relocated to the end while maintaining the relative order of non-zero elements [1, 3, 12].
Example 2
Input:nums = [0]
Output:[0]
Explanation: A single-element array containing zero remains unchanged.

⚖️Formal Constraints & Bounds

  • 1 <= nums.length <= 104

  • -231 <= nums[i] <= 231 - 1

Deep-Dive & Conceptual Insights

Core Insight

Separating discovery of non-zeroes from zero-filling avoids expensive O(N^2) element shifting.

Real-World Scenario & Production Applications

Sparse array compaction, memory garbage collection compaction phases, and streaming event buffer filtering.

Subproblems & Recurrence Decomposition3 Phases

🧩Subproblem 1: Non-Zero Write Pointer Setup

insert_pos tracks where the next non-zero value should be written, starting at index 0.

Mathematical Recurrence / Code Invariant
insert_pos = 0

Step-by-Step Execution Trace Table

Stepreadernums[reader]Actionnums Statewriter
1000 == 0 → skip[0, 1, 0, 3, 12]0
2111 != 0 → nums[0]=1, writer++[1, 1, 0, 3, 12]1
3200 == 0 → skip[1, 1, 0, 3, 12]1
4333 != 0 → nums[1]=3, writer++[1, 3, 0, 3, 12]2
541212 != 0 → nums[2]=12, writer++[1, 3, 12, 3, 12]3
Fill3..4—Zero-fill from writer=3 to end[1, 3, 12, 0, 0]3
Code Shape
Archetype Code Shape
Python
1writer = 0
2for reader in range(len(nums)):
3 if nums[reader] != 0:
4 nums[writer] = nums[reader]
5 writer += 1
6for i in range(writer, len(nums)):
7 nums[i] = 0
8return nums

Conceptual Narrative

🧭 Conceptual Foundation & Pattern Intuition

Moving zeroes to the end of an array while maintaining the relative order of non-zero elements is the canonical Slow/Fast Reader-Writer Partitioning pattern. Rather than shifting elements backward upon discovering a zero (O(N2)O(N^2)O(N2) time), we decouple the role of scanning elements from the role of writing validated data. The writer pointer w maintains the frontier of clean non-zero elements, while the reader pointer r traverses ahead to inspect candidates.

🏟️ The Analogy: The Snowplow on a Highway

Imagine a snowplow (r) driving down a multi-lane highway covered in snowdrifts (0s) and stranded cars (non-zero numbers). Behind the plow follows a tow truck (w). Whenever the plow finds a working car, it radios the tow truck, which parks it at the earliest open lane slot (w). Once the highway has been inspected, all working cars are packed neatly at the beginning of the road; the rest of the highway behind them is simply paved over with asphalt (0s).

🔑 Why It Works

By swapping nums[w] and nums[r] instead of performing a two-pass overwrite, the algorithm automatically moves zeros backward without requiring a second zero-fill loop! When w == r, the element swaps with itself (a no-op). When zeroes have been encountered, w lags behind r, pointing precisely to the leftmost zero waiting to receive the next non-zero car.

  • Overwriting non-zero values with zero prematurely: When using separate read and write pointers, writing nums[writer] = 0 during the initial compaction pass will overwrite unprocessed non-zero values ahead of it. Only fill remaining slots with zeros after the reader pass finishes.

  • Redundant self-assignment when no zeros have been encountered: If all initial elements are non-zero, reader == writer. Writing nums[writer] = nums[reader] or swapping on every step does redundant memory writes. Guard with if reader != writer:.

  • Incomplete zero-fill at array tail: After moving all non-zero elements to [0..writer-1], forgetting the second pass while writer < len(nums): nums[writer] = 0; writer += 1 leaves stale duplicate values at the tail.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

In-place array filtering + relative ordering preservation + constant space requirement.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Invariant: nums[0..writer-1] contains all non-zero elements encountered so far in relative order.

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

  • Using expensive nested array deletion / splice operations: O(N^2) trap.

The 60-Second Interview Pitch

Say this out loud before you type a single line

"I iterate with a reader pointer. When nums[reader] is non-zero, I write it to nums[writer] and increment writer. After the loop, I fill indices from writer to the end with zeroes. 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: Fast pointer scans array; on non-zero, swaps with slow pointer or writes to slow pointer index and advances. Single linear pass.

SPACE COMPLEXITY

O(1) Auxiliary

Look at memory allocations: Call stack uses O(1) Iterative. Modifies array in-place with two scalar pointer indices.

Formal Recurrence Relation

T(N) = O(N)

Derivation Progression

Single Scan Pass

for r ∈ [0, N-1]

Right pointer traverses the array from 0 to N-1.

In-Place Swap

nums[l], nums[r] = nums[r], nums[l]

Maintains invariant that nums[0..l-1] contains non-zero elements in original order.

Total Work

N iterations × O(1) = O(N)

Every element is inspected once and swapped at most once.

Variable Definitions

NNN

Total number of elements in the array

Memory Architecture & Bounds

🟣 Call Stack

O(1) Iterative

🔵 Auxiliary Heap

O(1) Two scalar pointers

🟢 Output Space

O(1) In-place array modification

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: "move all 0's to the end", "maintain relative order of non-zero elements", "in-place without copying the array". Compaction and snowplow pattern: all non-zero elements must be compacted into the prefix, leaving zeros trailing.

CONSTRAINTS & BOUNDS

1≤N≤1041 \le N \le 10^41≤N≤104. Time budget O(N)O(N)O(N) single pass, auxiliary space O(1)O(1)O(1).

FAANG PRODUCTION TRAPS & EDGE CASES

Overwriting elements instead of swapping (which requires a second loop to fill zeros). When array has no zeros, slow == fast; swapping nums[slow], nums[fast] is an identity operation that safely preserves order.

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