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•Dynamic Programming
MediumLC 53

Maximum Subarray (LeetCode 53)

Target Frequency:AmazonMicrosoftGoogle

You're given an integer array nums. A subarray is any non-empty run of elements sitting next to each other in the array, with no skipping.

Scan every possible subarray and return the largest sum any of them adds up to.

Worked Examples

Example 1
Input:nums = [-2,1,-3,4,-1,2,1,-5,4]
Output:6
Explanation: The subarray [4,-1,2,1] has the largest sum 6.
Example 2
Input:nums = [1]
Output:1
Explanation: The subarray [1] has the largest sum 1.
Example 3
Input:nums = [5,4,-1,7,8]
Output:23
Explanation: The subarray [5,4,-1,7,8] has the largest sum 23.

⚖️Formal Constraints & Bounds

  • 1 <= nums.length <= 105

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

Deep-Dive & Conceptual Insights

Core Insight

Negative running prefix sums are dropped immediately to maximize downstream totals.

Real-World Scenario & Production Applications

Maximum profit period in stock price differentials, high-intensity signal interval detection.

Subproblems & Recurrence Decomposition3 Phases

🧩Subproblem 1: Kadane Prefix Reset Decision

At each element nums[i], decide whether to extend the existing contiguous subarray (curr_sum + nums[i]) or discard a negative prefix and start fresh at nums[i].

Mathematical Recurrence / Code Invariant
curr_sum = max(nums[i], curr_sum + nums[i])

Step-by-Step Execution Trace Table

Element xcurr_sum = max(x, curr+x)best_sumSubarray State
-2-2-2[-2]
111[1] (Reset)
-3-21[1, -3]
444[4] (Reset)
-134[4, -1]
255[4, -1, 2]
166[4, -1, 2, 1]
Code Shape
Archetype Code Shape
Python
1curr = best = nums[0]
2for x in nums[1:]:
3 curr = max(x, curr + x)
4 best = max(best, curr)
5return best

Conceptual Narrative

🧭 Conceptual Foundation & Pattern Intuition
Code / Blueprint
Kadane's algorithm resolves the maximum contiguous subarray sum in a single linear pass. At each index $i$, the optimal contiguous subarray ending at $i$ either extends the previous subarray ($current_sum + nums[i]$) or discards negative accumulated baggage to start fresh at $nums[i]$: $current_sum = \max(nums[i], current_sum + nums[i])$. Tracking the maximum of these local values yields the global maximum in $O(N)$ time and $O(1)$ space.
 
🎒 The Analogy: Dropping a Negative Running Total Mid-Hike

Imagine carrying a running total of "profit so far" as you walk a trail collecting and losing money at each step. If your running total ever goes negative, carrying it forward into the next step can only lower whatever you collect next. So the moment your total dips below zero, you drop it entirely and start fresh from the next step, as if today were day one. If your total is still positive, it's still an asset worth carrying forward.

🔑 The Key Idea in the Code

curr and best answer two different questions: curr is "the best subarray ending right here," which can reset at any point, while best is "the best subarray seen anywhere so far," which only ever grows. Losing track of this distinction is the most common bug when writing Kadane's from memory.

  • All-negative array sentinel reset: Initializing max_sum = 0. If nums = [-3, -2, -1], resetting to 0 returns 0 instead of -1. Initialize max_sum = nums[0].

  • Resetting current sum before updating global max: Resetting curr = max(0, curr) before evaluating max_sum = max(max_sum, curr). On all-negative arrays, this corrupts the answer. Always compute curr = max(x, curr + x) first.

  • Confusing contiguous subarray with subsequence: A subarray must be contiguous; sorting the array or skipping negative numbers to pick positive values violates problem constraints.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

Max contiguous subarray sum with negative and positive values.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Invariant: curr is the best sum of a subarray that ends at the current index, and best is the largest curr seen so far.

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

  • Comparing curr + x with 0 instead of with x: this allows an empty subarray.

  • Returning curr instead of best: the best subarray can end before the last number.

The 60-Second Interview Pitch

Say this out loud before you type a single line

"I start with curr = best = nums[0]. For each number x in nums[1:], I update curr = max(x, curr + x) and best = max(best, curr). I return best. 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: Kadane's algorithm: curr_max = max(nums[i], curr_max + nums[i]). If running sum drops below 0, resets with current element. Single pass through N elements.

SPACE COMPLEXITY

O(1) Auxiliary

Look at memory allocations: Call stack uses O(1) Iterative. Only stores curr_max and global_max scalar variables.

Formal Recurrence Relation

T(N) = N · O(1) = O(N)

Derivation Progression

Prefix Reset Decision

Si = max(nums[i], Si-1 + nums[i])

Extends previous subarray or starts fresh at nums[i] if previous sum was negative.

Global Maximum Tracking

M = max(M, Si)

Updates best seen subarray sum in O(1).

Single Pass

N iterations = O(N)

Examines each array value exactly 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 registers

🟢 Output Space

O(1) Max sum 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)

State-Space & Subproblem DAG(Directed Acyclic Graph) Topology

State-Space & Subproblem DAG(Directed Acyclic Graph) Topology
Synthesizing vector architecture diagram...
Staff+ Engineering Perspective

Senior SWE Deconstruction & Hardware Caveats

ARCHITECTURAL SIGNALS & INTERVIEW TRIGGERS

Triggers: "subarray with the largest sum". Kadane's Algorithm: at each position, decide whether to append current element to the existing running sum OR restart a new subarray from the current element.

CONSTRAINTS & BOUNDS

N≤105N \le 10^5N≤105. Strictly O(N)O(N)O(N) linear time single pass.

FAANG PRODUCTION TRAPS & EDGE CASES

All negative numbers (e.g. [-3, -2, -5]): initializing max_sum = 0 produces false answers; must initialize max_sum = nums[0].

Theory Context•Dynamic Programming
MediumLC 53

Maximum Subarray (LeetCode 53)

Target Frequency:AmazonMicrosoftGoogle

You're given an integer array nums. A subarray is any non-empty run of elements sitting next to each other in the array, with no skipping.

Scan every possible subarray and return the largest sum any of them adds up to.

Worked Examples

Example 1
Input:nums = [-2,1,-3,4,-1,2,1,-5,4]
Output:6
Explanation: The subarray [4,-1,2,1] has the largest sum 6.
Example 2
Input:nums = [1]
Output:1
Explanation: The subarray [1] has the largest sum 1.
Example 3
Input:nums = [5,4,-1,7,8]
Output:23
Explanation: The subarray [5,4,-1,7,8] has the largest sum 23.

⚖️Formal Constraints & Bounds

  • 1 <= nums.length <= 105

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

Deep-Dive & Conceptual Insights

Core Insight

Negative running prefix sums are dropped immediately to maximize downstream totals.

Real-World Scenario & Production Applications

Maximum profit period in stock price differentials, high-intensity signal interval detection.

Subproblems & Recurrence Decomposition3 Phases

🧩Subproblem 1: Kadane Prefix Reset Decision

At each element nums[i], decide whether to extend the existing contiguous subarray (curr_sum + nums[i]) or discard a negative prefix and start fresh at nums[i].

Mathematical Recurrence / Code Invariant
curr_sum = max(nums[i], curr_sum + nums[i])

Step-by-Step Execution Trace Table

Element xcurr_sum = max(x, curr+x)best_sumSubarray State
-2-2-2[-2]
111[1] (Reset)
-3-21[1, -3]
444[4] (Reset)
-134[4, -1]
255[4, -1, 2]
166[4, -1, 2, 1]
Code Shape
Archetype Code Shape
Python
1curr = best = nums[0]
2for x in nums[1:]:
3 curr = max(x, curr + x)
4 best = max(best, curr)
5return best

Conceptual Narrative

🧭 Conceptual Foundation & Pattern Intuition
Code / Blueprint
Kadane's algorithm resolves the maximum contiguous subarray sum in a single linear pass. At each index $i$, the optimal contiguous subarray ending at $i$ either extends the previous subarray ($current_sum + nums[i]$) or discards negative accumulated baggage to start fresh at $nums[i]$: $current_sum = \max(nums[i], current_sum + nums[i])$. Tracking the maximum of these local values yields the global maximum in $O(N)$ time and $O(1)$ space.
 
🎒 The Analogy: Dropping a Negative Running Total Mid-Hike

Imagine carrying a running total of "profit so far" as you walk a trail collecting and losing money at each step. If your running total ever goes negative, carrying it forward into the next step can only lower whatever you collect next. So the moment your total dips below zero, you drop it entirely and start fresh from the next step, as if today were day one. If your total is still positive, it's still an asset worth carrying forward.

🔑 The Key Idea in the Code

curr and best answer two different questions: curr is "the best subarray ending right here," which can reset at any point, while best is "the best subarray seen anywhere so far," which only ever grows. Losing track of this distinction is the most common bug when writing Kadane's from memory.

  • All-negative array sentinel reset: Initializing max_sum = 0. If nums = [-3, -2, -1], resetting to 0 returns 0 instead of -1. Initialize max_sum = nums[0].

  • Resetting current sum before updating global max: Resetting curr = max(0, curr) before evaluating max_sum = max(max_sum, curr). On all-negative arrays, this corrupts the answer. Always compute curr = max(x, curr + x) first.

  • Confusing contiguous subarray with subsequence: A subarray must be contiguous; sorting the array or skipping negative numbers to pick positive values violates problem constraints.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

Max contiguous subarray sum with negative and positive values.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Invariant: curr is the best sum of a subarray that ends at the current index, and best is the largest curr seen so far.

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

  • Comparing curr + x with 0 instead of with x: this allows an empty subarray.

  • Returning curr instead of best: the best subarray can end before the last number.

The 60-Second Interview Pitch

Say this out loud before you type a single line

"I start with curr = best = nums[0]. For each number x in nums[1:], I update curr = max(x, curr + x) and best = max(best, curr). I return best. 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: Kadane's algorithm: curr_max = max(nums[i], curr_max + nums[i]). If running sum drops below 0, resets with current element. Single pass through N elements.

SPACE COMPLEXITY

O(1) Auxiliary

Look at memory allocations: Call stack uses O(1) Iterative. Only stores curr_max and global_max scalar variables.

Formal Recurrence Relation

T(N) = N · O(1) = O(N)

Derivation Progression

Prefix Reset Decision

Si = max(nums[i], Si-1 + nums[i])

Extends previous subarray or starts fresh at nums[i] if previous sum was negative.

Global Maximum Tracking

M = max(M, Si)

Updates best seen subarray sum in O(1).

Single Pass

N iterations = O(N)

Examines each array value exactly 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 registers

🟢 Output Space

O(1) Max sum 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)

State-Space & Subproblem DAG(Directed Acyclic Graph) Topology

State-Space & Subproblem DAG(Directed Acyclic Graph) Topology
Synthesizing vector architecture diagram...
Staff+ Engineering Perspective

Senior SWE Deconstruction & Hardware Caveats

ARCHITECTURAL SIGNALS & INTERVIEW TRIGGERS

Triggers: "subarray with the largest sum". Kadane's Algorithm: at each position, decide whether to append current element to the existing running sum OR restart a new subarray from the current element.

CONSTRAINTS & BOUNDS

N≤105N \le 10^5N≤105. Strictly O(N)O(N)O(N) linear time single pass.

FAANG PRODUCTION TRAPS & EDGE CASES

All negative numbers (e.g. [-3, -2, -5]): initializing max_sum = 0 produces false answers; must initialize max_sum = nums[0].

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