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 918

Maximum Sum Circular Subarray (LeetCode 918)

Target Frequency:AmazonGoogleMicrosoft

You get an integer array nums that is circular: the number after the last one is the first one again. A subarray is a run of numbers that sit next to each other, and it may wrap around the end.

Find the largest sum of a non-empty subarray. A subarray can use each position at most once.

Worked Examples

Example 1
Input:nums = [1,-2,3,-2]
Output:3
Explanation: The subarray [3] has the largest sum, 3.
Example 2
Input:nums = [5,-3,5]
Output:10
Explanation: The subarray [5, 5] wraps around from the last number to the first, and its sum is 10.
Example 3
Input:nums = [-3,-2,-3]
Output:-2
Explanation: Every number is negative, so the best subarray is the single number -2.

⚖️Formal Constraints & Bounds

  • 1 <= nums.length <= 3 * 104

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

Deep-Dive & Conceptual Insights

Core Insight

A run that wraps around the end is the whole array without one plain run in the middle, so the best wrapping run is the total minus the worst plain run: run Kadane's Algorithm once for the best and once, mirrored, for the worst.

Real-World Scenario & Production Applications

Any repeating cycle, such as a day of hourly profits that is followed by the same day again: the best stretch may start in the evening and continue into the next morning.

Step-by-Step Execution Trace Table

Trace of Example 2: nums = [5, -3, 5]. curr_max, curr_min, best and worst start at 5, and total = 5.

xcurr_maxbestcurr_minworsttotal
-325-3-32
5772-37

The best plain run is 7. The worst plain run is -3, so the best wrapping run is total - worst = 7 - (-3) = 10. The answer is max(7, 10) = 10.

Code Shape
Archetype Code Shape
Python
1total = curr_max = curr_min = best = worst = nums[0]
2for x in nums[1:]:
3 curr_max = max(x, curr_max + x); curr_min = min(x, curr_min + x)
4 best = max(best, curr_max); worst = min(worst, curr_min); total += x
5return max(best, total - worst) if best > 0 else best

Conceptual Narrative

🧭 Conceptual Foundation & Pattern Intuition

In a circular array, the last number is followed by the first. A subarray is now either a plain run, or a run that wraps around the end. A run that wraps around is the whole array without one plain run in the middle. So the best wrapping run is the total minus the worst plain run.

➗ What Is Added To Kadane

Kadane's Algorithm finds the best plain run. This variant runs it a second time with min to find the worst plain run, and adds a running total. The answer is the larger of the best plain run and total - worst.

🔑 The Key Idea in the Code

If every number is negative, the worst plain run is the whole array, so total - worst is 0, which is an empty run. An empty run is not allowed, so when best is not positive the answer is best.

  • Treating the wrap as a second pass: a wrapping run is the total minus one plain run in the middle. Do not extend the array or loop twice.

  • Removing the best run instead of the worst: total - best is the part left over from the best run, not the best wrapping run. Remove the worst plain run.

  • Ignoring the all-negative array: the worst plain run is then the whole array, total - worst is an empty run, and the answer would be 0 instead of the largest negative number.

  • Forgetting to run the mirror of Kadane: worst needs its own curr_min with min, not best with a negative sign.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

"The array is circular" and "a subarray may wrap around": the best run is a plain run, or a run that holds the end and the start. A best sum over contiguous runs points to Kadane's Algorithm, and the wrap is the part that is new.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

best and worst are the best and the worst sum of a plain subarray, each found with the extend-or-restart rule. A wrapping run is total minus a plain run in the middle, so its best value is total - worst.

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

  • Forgetting the wrap: returning only best misses [5, -3, 5], where the answer wraps around.

The 60-Second Interview Pitch

Say this out loud before you type a single line

I'd solve this with Kadane's Algorithm run twice. A run in a circular array is either a plain run or one that wraps around the end, and a wrapping run is the whole array minus a plain run in the middle. So I run Kadane once with max for the best plain run, and once with min for the worst plain run, and I keep the total. The answer is the larger of the best plain run and the total minus the worst plain run. If every number is negative, the worst plain run is the whole array and the wrapping run would be empty, so I return the best plain run. That is one pass, order N time and order 1 space.

Big-O Invariant Derivation

Complexity & Mathematical Proof

TIME COMPLEXITY

O(N)

Look at the loop. for x in nums[1:] visits each number once. Each visit updates curr_max, curr_min, best, worst and total, which is constant work. That is N steps, so time is O(N).

SPACE COMPLEXITY

O(1)

The code keeps six variables, whatever the length of nums is. The circular array is never copied or doubled, so space is O(1).

Formal Recurrence Relation

T(N)=5N=O(N)T(N) = 5N = O(N)T(N)=5N=O(N)

Derivation Progression

Passes

N−1 numbersN - 1 \text{ numbers}N−1 numbers

for x in nums[1:] visits each number after the first once.

Work per number

5 = O(1)

Two extend-or-restart steps, two global updates and one addition to the total.

Total

5N = O(N)

Numbers times a constant amount of work.

Variable Definitions

NNN

Length of nums

bestbestbest

Best sum of a plain subarray

worstworstworst

Worst sum of a plain subarray

Memory Architecture & Bounds

🟣 Call Stack

O(1): a loop only, no recursion

🔵 Auxiliary Heap

O(1): the variables total, curr_max, curr_min, best and worst

🟢 Output Space

O(1): one integer

Boundary Best / Worst Cases

Best Case

O(N)O(N)O(N): the loop always visits every number.

Average Case

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

Worst Case

O(N)O(N)O(N): the same count.

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: "circular array", "largest sum of a non-empty subarray". A best sum over runs is Kadane's Algorithm, and "circular" adds the runs that wrap around the end.

CONSTRAINTS & BOUNDS

N≤3×104N \le 3 \times 10^4N≤3×104, so a loop over all start positions and lengths is 9×1089 \times 10^89×108 steps. One pass is O(N)O(N)O(N), and the sums stay below 9×1089 \times 10^89×108, which fits in 32 bits.

FAANG PRODUCTION TRAPS & EDGE CASES

When every number is negative, total - worst is 0 because the worst plain run is the whole array, and a 0 would mean an empty run. Guard it with best > 0. Doubling the array and running Kadane on it is wrong without a length limit, because a run could use a position twice.

Theory Context•Dynamic Programming
MediumLC 918

Maximum Sum Circular Subarray (LeetCode 918)

Target Frequency:AmazonGoogleMicrosoft

You get an integer array nums that is circular: the number after the last one is the first one again. A subarray is a run of numbers that sit next to each other, and it may wrap around the end.

Find the largest sum of a non-empty subarray. A subarray can use each position at most once.

Worked Examples

Example 1
Input:nums = [1,-2,3,-2]
Output:3
Explanation: The subarray [3] has the largest sum, 3.
Example 2
Input:nums = [5,-3,5]
Output:10
Explanation: The subarray [5, 5] wraps around from the last number to the first, and its sum is 10.
Example 3
Input:nums = [-3,-2,-3]
Output:-2
Explanation: Every number is negative, so the best subarray is the single number -2.

⚖️Formal Constraints & Bounds

  • 1 <= nums.length <= 3 * 104

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

Deep-Dive & Conceptual Insights

Core Insight

A run that wraps around the end is the whole array without one plain run in the middle, so the best wrapping run is the total minus the worst plain run: run Kadane's Algorithm once for the best and once, mirrored, for the worst.

Real-World Scenario & Production Applications

Any repeating cycle, such as a day of hourly profits that is followed by the same day again: the best stretch may start in the evening and continue into the next morning.

Step-by-Step Execution Trace Table

Trace of Example 2: nums = [5, -3, 5]. curr_max, curr_min, best and worst start at 5, and total = 5.

xcurr_maxbestcurr_minworsttotal
-325-3-32
5772-37

The best plain run is 7. The worst plain run is -3, so the best wrapping run is total - worst = 7 - (-3) = 10. The answer is max(7, 10) = 10.

Code Shape
Archetype Code Shape
Python
1total = curr_max = curr_min = best = worst = nums[0]
2for x in nums[1:]:
3 curr_max = max(x, curr_max + x); curr_min = min(x, curr_min + x)
4 best = max(best, curr_max); worst = min(worst, curr_min); total += x
5return max(best, total - worst) if best > 0 else best

Conceptual Narrative

🧭 Conceptual Foundation & Pattern Intuition

In a circular array, the last number is followed by the first. A subarray is now either a plain run, or a run that wraps around the end. A run that wraps around is the whole array without one plain run in the middle. So the best wrapping run is the total minus the worst plain run.

➗ What Is Added To Kadane

Kadane's Algorithm finds the best plain run. This variant runs it a second time with min to find the worst plain run, and adds a running total. The answer is the larger of the best plain run and total - worst.

🔑 The Key Idea in the Code

If every number is negative, the worst plain run is the whole array, so total - worst is 0, which is an empty run. An empty run is not allowed, so when best is not positive the answer is best.

  • Treating the wrap as a second pass: a wrapping run is the total minus one plain run in the middle. Do not extend the array or loop twice.

  • Removing the best run instead of the worst: total - best is the part left over from the best run, not the best wrapping run. Remove the worst plain run.

  • Ignoring the all-negative array: the worst plain run is then the whole array, total - worst is an empty run, and the answer would be 0 instead of the largest negative number.

  • Forgetting to run the mirror of Kadane: worst needs its own curr_min with min, not best with a negative sign.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

"The array is circular" and "a subarray may wrap around": the best run is a plain run, or a run that holds the end and the start. A best sum over contiguous runs points to Kadane's Algorithm, and the wrap is the part that is new.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

best and worst are the best and the worst sum of a plain subarray, each found with the extend-or-restart rule. A wrapping run is total minus a plain run in the middle, so its best value is total - worst.

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

  • Forgetting the wrap: returning only best misses [5, -3, 5], where the answer wraps around.

The 60-Second Interview Pitch

Say this out loud before you type a single line

I'd solve this with Kadane's Algorithm run twice. A run in a circular array is either a plain run or one that wraps around the end, and a wrapping run is the whole array minus a plain run in the middle. So I run Kadane once with max for the best plain run, and once with min for the worst plain run, and I keep the total. The answer is the larger of the best plain run and the total minus the worst plain run. If every number is negative, the worst plain run is the whole array and the wrapping run would be empty, so I return the best plain run. That is one pass, order N time and order 1 space.

Big-O Invariant Derivation

Complexity & Mathematical Proof

TIME COMPLEXITY

O(N)

Look at the loop. for x in nums[1:] visits each number once. Each visit updates curr_max, curr_min, best, worst and total, which is constant work. That is N steps, so time is O(N).

SPACE COMPLEXITY

O(1)

The code keeps six variables, whatever the length of nums is. The circular array is never copied or doubled, so space is O(1).

Formal Recurrence Relation

T(N)=5N=O(N)T(N) = 5N = O(N)T(N)=5N=O(N)

Derivation Progression

Passes

N−1 numbersN - 1 \text{ numbers}N−1 numbers

for x in nums[1:] visits each number after the first once.

Work per number

5 = O(1)

Two extend-or-restart steps, two global updates and one addition to the total.

Total

5N = O(N)

Numbers times a constant amount of work.

Variable Definitions

NNN

Length of nums

bestbestbest

Best sum of a plain subarray

worstworstworst

Worst sum of a plain subarray

Memory Architecture & Bounds

🟣 Call Stack

O(1): a loop only, no recursion

🔵 Auxiliary Heap

O(1): the variables total, curr_max, curr_min, best and worst

🟢 Output Space

O(1): one integer

Boundary Best / Worst Cases

Best Case

O(N)O(N)O(N): the loop always visits every number.

Average Case

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

Worst Case

O(N)O(N)O(N): the same count.

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: "circular array", "largest sum of a non-empty subarray". A best sum over runs is Kadane's Algorithm, and "circular" adds the runs that wrap around the end.

CONSTRAINTS & BOUNDS

N≤3×104N \le 3 \times 10^4N≤3×104, so a loop over all start positions and lengths is 9×1089 \times 10^89×108 steps. One pass is O(N)O(N)O(N), and the sums stay below 9×1089 \times 10^89×108, which fits in 32 bits.

FAANG PRODUCTION TRAPS & EDGE CASES

When every number is negative, total - worst is 0 because the worst plain run is the whole array, and a 0 would mean an empty run. Guard it with best > 0. Doubling the array and running Kadane on it is wrong without a length limit, because a run could use a position twice.

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