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 1186

Maximum Subarray Sum with One Deletion (LeetCode 1186)

Target Frequency:AmazonGoogleMicrosoft

You get an integer array arr. Choose a subarray, a run of numbers that sit next to each other. You may delete at most one number from the subarray. After the deletion, the subarray must still hold at least one number.

Return the largest possible sum of the subarray after the optional deletion.

Worked Examples

Example 1
Input:arr = [1,-2,0,3]
Output:4
Explanation: Take [1, -2, 0, 3] and delete -2. The remaining numbers 1, 0, 3 sum to 4.
Example 2
Input:arr = [1,-2,-2,3]
Output:3
Explanation: The single number [3] has sum 3. Deleting one -2 still leaves another -2 in the run, so no larger sum exists.
Example 3
Input:arr = [-1,-1,-1,-1]
Output:-1
Explanation: Every number is negative, so the best subarray is one number, -1. The deletion cannot leave an empty subarray.

⚖️Formal Constraints & Bounds

  • 1 <= arr.length <= 105

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

Deep-Dive & Conceptual Insights

Core Insight

A run that may delete one number has two states ending at each position: nothing deleted yet (keep) and one number deleted (drop). Deleting x turns the old keep into a drop, and any later number is added to drop, so drop must be computed from the keep that came before x.

Real-World Scenario & Production Applications

A run of daily profits where one bad day may be ignored, such as a single failed day that can be written off: the best stretch is the best sum of days after dropping at most one of them.

Step-by-Step Execution Trace Table

Trace of Example 1: arr = [1, -2, 0, 3]. keep = best = 1 and drop = -inf.

xdrop = max(keep, drop + x)keep = max(x, keep + x)best
-2max(1, -inf) = 1max(-2, -1) = -11
0max(-1, 1 + 0) = 1max(0, -1) = 01
3max(0, 1 + 3) = 4max(3, 3) = 34

At x = -2, deleting it gives drop = 1, the run [1]. At x = 3, drop = 1 + 3 = 4 extends that run to [1, 0, 3].

Code Shape
Archetype Code Shape
Python
1keep = best = arr[0]; drop = float('-inf')
2for x in arr[1:]:
3 drop = max(keep, drop + x)
4 keep = max(x, keep + x)
5 best = max(best, keep, drop)
6return best

Conceptual Narrative

🧭 Conceptual Foundation & Pattern Intuition

Kadane's Algorithm keeps the best run ending here. If you may delete one number from the run, the run has two possible states: nothing is deleted yet (keep), or one number is already deleted (drop). Each new number x updates both. Deleting x itself turns the old keep into a drop.

➗ What Is Added To Kadane

Kadane's Algorithm gets one more piece of state, drop. The keep update is the unchanged Kadane step. The new line is drop = max(keep, drop + x): delete x, or add x to a run that has already deleted a number.

🔑 The Key Idea in the Code

drop is updated before keep, so it uses the keep from before x. If keep is updated first, drop would delete a number from a run that already includes x.

  • Updating keep before drop: drop deletes x from the best run that ended before x. If keep already includes x, drop deletes a number from a run that contains x.

  • Letting the deletion leave an empty subarray: max(0, ...) in drop counts the empty subarray. When every number is negative, the answer is the largest number, not 0.

  • Returning only the Kadane value: best = max(best, keep) never uses the deletion, so [1, -3, 1] returns 1 instead of 2.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

"The maximum sum of a subarray, with at most one deletion": a best sum over contiguous runs is Kadane's Algorithm, and the deletion budget of one means the run can be in two states: before the deletion and after it.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

keep is the best sum of a subarray ending at x with nothing deleted. drop is the best sum ending at x with exactly one number deleted. Deleting x gives the old keep; deleting earlier gives drop + x. best takes keep and drop at every index.

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'd solve this with Kadane's Algorithm and one extra state for the deletion. Keep is the best sum of a subarray ending at the current number with nothing deleted. Drop is the best sum ending there with one number deleted. For each number x, drop is the larger of keep, which deletes x itself, and drop plus x, which adds x to a run that already deleted a number. I update drop first, so it uses the keep from before x. Then keep is the usual Kadane step. Best takes both. 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 arr[1:] visits each number once. Each visit updates drop, keep and best with one max each, which is constant work. That is N - 1 steps, so time is O(N).

SPACE COMPLEXITY

O(1)

The code keeps three variables, keep, drop and best, whatever the length of arr is. There is no table and no recursion, so space is O(1).

Formal Recurrence Relation

T(N)=3(N−1)=O(N)T(N) = 3(N - 1) = O(N)T(N)=3(N−1)=O(N)

Derivation Progression

Passes

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

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

Work per number

3 = O(1)

One max for drop, one for keep and one for best.

Total

3(N - 1) = O(N)

Numbers times a constant amount of work.

Variable Definitions

NNN

Length of arr

keepkeepkeep

Best sum of a subarray ending here with nothing deleted

dropdropdrop

Best sum of a subarray ending here with one number deleted

Memory Architecture & Bounds

🟣 Call Stack

O(1): a loop only, no recursion

🔵 Auxiliary Heap

O(1): the variables keep, drop and best

🟢 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: "maximum sum of a subarray", "delete at most one element". A best sum over runs is Kadane's Algorithm, and a deletion budget of one adds a second state: before the deletion and after it.

CONSTRAINTS & BOUNDS

N≤105N \le 10^5N≤105 and ∣arr[i]∣≤104|arr[i]| \le 10^4∣arr[i]∣≤104, so a sum is at most 10910^9109, which fits in 32 bits. Trying every deletion inside every subarray is O(N3)O(N^3)O(N3). One pass is O(N)O(N)O(N).

FAANG PRODUCTION TRAPS & EDGE CASES

drop starts at minus infinity. With float('-inf'), drop + x stays minus infinity in Python. In a fixed-width language, use a very negative number such as half the minimum integer, so that adding to it never overflows.

Theory Context•Dynamic Programming
MediumLC 1186

Maximum Subarray Sum with One Deletion (LeetCode 1186)

Target Frequency:AmazonGoogleMicrosoft

You get an integer array arr. Choose a subarray, a run of numbers that sit next to each other. You may delete at most one number from the subarray. After the deletion, the subarray must still hold at least one number.

Return the largest possible sum of the subarray after the optional deletion.

Worked Examples

Example 1
Input:arr = [1,-2,0,3]
Output:4
Explanation: Take [1, -2, 0, 3] and delete -2. The remaining numbers 1, 0, 3 sum to 4.
Example 2
Input:arr = [1,-2,-2,3]
Output:3
Explanation: The single number [3] has sum 3. Deleting one -2 still leaves another -2 in the run, so no larger sum exists.
Example 3
Input:arr = [-1,-1,-1,-1]
Output:-1
Explanation: Every number is negative, so the best subarray is one number, -1. The deletion cannot leave an empty subarray.

⚖️Formal Constraints & Bounds

  • 1 <= arr.length <= 105

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

Deep-Dive & Conceptual Insights

Core Insight

A run that may delete one number has two states ending at each position: nothing deleted yet (keep) and one number deleted (drop). Deleting x turns the old keep into a drop, and any later number is added to drop, so drop must be computed from the keep that came before x.

Real-World Scenario & Production Applications

A run of daily profits where one bad day may be ignored, such as a single failed day that can be written off: the best stretch is the best sum of days after dropping at most one of them.

Step-by-Step Execution Trace Table

Trace of Example 1: arr = [1, -2, 0, 3]. keep = best = 1 and drop = -inf.

xdrop = max(keep, drop + x)keep = max(x, keep + x)best
-2max(1, -inf) = 1max(-2, -1) = -11
0max(-1, 1 + 0) = 1max(0, -1) = 01
3max(0, 1 + 3) = 4max(3, 3) = 34

At x = -2, deleting it gives drop = 1, the run [1]. At x = 3, drop = 1 + 3 = 4 extends that run to [1, 0, 3].

Code Shape
Archetype Code Shape
Python
1keep = best = arr[0]; drop = float('-inf')
2for x in arr[1:]:
3 drop = max(keep, drop + x)
4 keep = max(x, keep + x)
5 best = max(best, keep, drop)
6return best

Conceptual Narrative

🧭 Conceptual Foundation & Pattern Intuition

Kadane's Algorithm keeps the best run ending here. If you may delete one number from the run, the run has two possible states: nothing is deleted yet (keep), or one number is already deleted (drop). Each new number x updates both. Deleting x itself turns the old keep into a drop.

➗ What Is Added To Kadane

Kadane's Algorithm gets one more piece of state, drop. The keep update is the unchanged Kadane step. The new line is drop = max(keep, drop + x): delete x, or add x to a run that has already deleted a number.

🔑 The Key Idea in the Code

drop is updated before keep, so it uses the keep from before x. If keep is updated first, drop would delete a number from a run that already includes x.

  • Updating keep before drop: drop deletes x from the best run that ended before x. If keep already includes x, drop deletes a number from a run that contains x.

  • Letting the deletion leave an empty subarray: max(0, ...) in drop counts the empty subarray. When every number is negative, the answer is the largest number, not 0.

  • Returning only the Kadane value: best = max(best, keep) never uses the deletion, so [1, -3, 1] returns 1 instead of 2.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

"The maximum sum of a subarray, with at most one deletion": a best sum over contiguous runs is Kadane's Algorithm, and the deletion budget of one means the run can be in two states: before the deletion and after it.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

keep is the best sum of a subarray ending at x with nothing deleted. drop is the best sum ending at x with exactly one number deleted. Deleting x gives the old keep; deleting earlier gives drop + x. best takes keep and drop at every index.

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'd solve this with Kadane's Algorithm and one extra state for the deletion. Keep is the best sum of a subarray ending at the current number with nothing deleted. Drop is the best sum ending there with one number deleted. For each number x, drop is the larger of keep, which deletes x itself, and drop plus x, which adds x to a run that already deleted a number. I update drop first, so it uses the keep from before x. Then keep is the usual Kadane step. Best takes both. 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 arr[1:] visits each number once. Each visit updates drop, keep and best with one max each, which is constant work. That is N - 1 steps, so time is O(N).

SPACE COMPLEXITY

O(1)

The code keeps three variables, keep, drop and best, whatever the length of arr is. There is no table and no recursion, so space is O(1).

Formal Recurrence Relation

T(N)=3(N−1)=O(N)T(N) = 3(N - 1) = O(N)T(N)=3(N−1)=O(N)

Derivation Progression

Passes

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

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

Work per number

3 = O(1)

One max for drop, one for keep and one for best.

Total

3(N - 1) = O(N)

Numbers times a constant amount of work.

Variable Definitions

NNN

Length of arr

keepkeepkeep

Best sum of a subarray ending here with nothing deleted

dropdropdrop

Best sum of a subarray ending here with one number deleted

Memory Architecture & Bounds

🟣 Call Stack

O(1): a loop only, no recursion

🔵 Auxiliary Heap

O(1): the variables keep, drop and best

🟢 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: "maximum sum of a subarray", "delete at most one element". A best sum over runs is Kadane's Algorithm, and a deletion budget of one adds a second state: before the deletion and after it.

CONSTRAINTS & BOUNDS

N≤105N \le 10^5N≤105 and ∣arr[i]∣≤104|arr[i]| \le 10^4∣arr[i]∣≤104, so a sum is at most 10910^9109, which fits in 32 bits. Trying every deletion inside every subarray is O(N3)O(N^3)O(N3). One pass is O(N)O(N)O(N).

FAANG PRODUCTION TRAPS & EDGE CASES

drop starts at minus infinity. With float('-inf'), drop + x stays minus infinity in Python. In a fixed-width language, use a very negative number such as half the minimum integer, so that adding to it never overflows.

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