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 1014

Best Sightseeing Pair (LeetCode 1014)

You get an integer array values. Each position is one sightseeing spot along a road, and values[i] is how good spot i is. A pair is two different spots i and j with i < j.

The score of a pair is the two values added together, minus the distance between the spots: values[i] + values[j] - (j - i). Return the highest score that any pair can have.

Worked Examples

Example 1
Input:values = [8,1,5,2,6]
Output:11
Explanation: Take the spots at positions 0 and 2. The score is 8 + 5 - 2 = 11. Every other pair scores less.
Example 2
Input:values = [1,2]
Output:2
Explanation: There is one pair, the spots at positions 0 and 1. The score is 1 + 2 - 1 = 2.

⚖️Formal Constraints & Bounds

  • 2 <= values.length <= 5 * 104

  • 1 <= values[i] <= 1000

Deep-Dive & Conceptual Insights

Core Insight

The score splits into a part that needs only the left spot, values[i] + i, and a part that needs only the right spot, values[j] - j. So for each right spot the best partner is the earlier spot with the largest values[i] + i, and one carried maximum replaces the search over all pairs.

Real-World Scenario & Production Applications

A tour guide picks two stops on one road. Each stop has a rating, and every stop between the two costs one point of walking. The best tour is the pair with the highest ratings and the least walking.

Step-by-Step Execution Trace Table

Trace of Example 1: values = [8, 1, 5, 2, 6]. best_left = 8 (spot 0, 8 + 0) and best = -inf.

jvalues[j]best = max(best, best_left + values[j] - j)best_left = max(best_left, values[j] + j)
11max(-inf, 8 + 1 - 1) = 8max(8, 1 + 1) = 8
25max(8, 8 + 5 - 2) = 11max(8, 5 + 2) = 8
32max(11, 8 + 2 - 3) = 11max(8, 2 + 3) = 8
46max(11, 8 + 6 - 4) = 11max(8, 6 + 4) = 10

At j = 2, the best earlier spot is spot 0, so the score is 11. At j = 4, best_left is still 8, because best_left is updated with spot 4 only after spot 4 is scored.

Code Shape
Archetype Code Shape
Python
1best_left = values[0]; best = float('-inf')
2for j in range(1, len(values)):
3 best = max(best, best_left + values[j] - j)
4 best_left = max(best_left, values[j] + j)
5return best

Conceptual Narrative

🧭 Conceptual Foundation & Pattern Intuition

A pair of spots i < j has the score values[i] + values[j] + i - j. Trying every pair takes N * (N - 1) / 2 checks. The score can be regrouped as (values[i] + i) + (values[j] - j). The first part needs only i. The second part needs only j.

➗ What Is Carried From The Left

For one right end j, the second part is fixed. The best score for j uses the earlier spot with the largest values[i] + i. One variable, best_left, keeps that largest value. It is the whole state of the DP.

🔑 The Key Idea in the Code

The loop scores j first and updates best_left with j second. If the order is reversed, best_left already contains spot j, and the spot is paired with itself.

  • Updating best_left with spot j before scoring j: best_left then contains spot j, and the pair uses the same spot twice. [8, 1, 5, 2, 6] returns 12 instead of 11.

  • Carrying values[i] instead of values[i] + i: the distance is part of the left term. [1, 1, 1, 1, 9] returns 6 instead of 9.

  • Leaving out - j from the score: the distance is never subtracted. [8, 1, 5, 2, 6] returns 14 instead of 11.

  • Starting the loop at j = 0: spot 0 is scored against itself. [8, 1, 5, 2, 6] returns 16 instead of 11.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

"Maximum score of a pair of spots" with the score values[i] + values[j] + i - j: the pair must be in order (i < j), and the score adds a term for i and a term for j. When a pair score separates into one term for each end, the best left end can be carried while the loop moves right.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Before spot j is scored, best_left is the largest values[i] + i over all spots i < j, and best is the largest score of any pair that ends before j. The score of j is best_left + values[j] - j.

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 the best left half carry. The score values i plus values j plus i minus j can be regrouped as values i plus i, plus values j minus j. The first part needs only the left spot and the second part needs only the right spot. So for each right spot j, the best partner is the earlier spot with the largest values i plus i. I keep that in one variable, best left, which starts as the first spot. For each j from one on, I first score the pair, best left plus values j minus j, and keep the maximum. Only after that, I update best left with values j plus j. If I updated first, j would pair with itself. 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 j in range(1, len(values)) visits each spot after the first once. Each visit does one max to score j and one max to update best_left, which is constant work. That is N - 1 steps, so time is O(N).

SPACE COMPLEXITY

O(1)

The code keeps two variables, best_left and best, whatever the length of values is. There is no table and no recursion, so space is O(1).

Formal Recurrence Relation

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

Derivation Progression

Passes

N−1 spotsN - 1 \text{ spots}N−1 spots

for j in range(1, len(values)) visits each spot after the first once.

Work per spot

2 = O(1)

One max for best and one max for best_left.

Total

2(N - 1) = O(N)

Spots times a constant amount of work.

Variable Definitions

NNN

Length of values

bestleftbest_leftbestl​eft

Largest values[i] + i over the spots before j

bestbestbest

Largest pair score found so far

Memory Architecture & Bounds

🟣 Call Stack

O(1): a loop only, no recursion

🔵 Auxiliary Heap

O(1): the variables best_left 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 spot.

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 score of a pair of spots", "i < j". A pair score that adds a term for each end and subtracts the distance can be regrouped into a left part and a right part, so the best left end is carried while the loop moves right.

CONSTRAINTS & BOUNDS

N≤5×104N \le 5 \times 10^4N≤5×104 and 1≤values[i]≤10001 \le values[i] \le 10001≤values[i]≤1000. Scoring every pair is about 1.25×1091.25 \times 10^91.25×109 pairs in the worst case, which is too slow. One pass is O(N)O(N)O(N). The carried value values[i] + i is at most about 5×1045 \times 10^45×104, so 32-bit integers are enough.

FAANG PRODUCTION TRAPS & EDGE CASES

Updating best_left before scoring j pairs j with itself, and [8, 1, 5, 2, 6] returns 12 instead of 11. Starting the loop at j = 0 does the same with spot 0. best starts at minus infinity so that the first real score replaces it.

Theory Context•Dynamic Programming
MediumLC 1014

Best Sightseeing Pair (LeetCode 1014)

You get an integer array values. Each position is one sightseeing spot along a road, and values[i] is how good spot i is. A pair is two different spots i and j with i < j.

The score of a pair is the two values added together, minus the distance between the spots: values[i] + values[j] - (j - i). Return the highest score that any pair can have.

Worked Examples

Example 1
Input:values = [8,1,5,2,6]
Output:11
Explanation: Take the spots at positions 0 and 2. The score is 8 + 5 - 2 = 11. Every other pair scores less.
Example 2
Input:values = [1,2]
Output:2
Explanation: There is one pair, the spots at positions 0 and 1. The score is 1 + 2 - 1 = 2.

⚖️Formal Constraints & Bounds

  • 2 <= values.length <= 5 * 104

  • 1 <= values[i] <= 1000

Deep-Dive & Conceptual Insights

Core Insight

The score splits into a part that needs only the left spot, values[i] + i, and a part that needs only the right spot, values[j] - j. So for each right spot the best partner is the earlier spot with the largest values[i] + i, and one carried maximum replaces the search over all pairs.

Real-World Scenario & Production Applications

A tour guide picks two stops on one road. Each stop has a rating, and every stop between the two costs one point of walking. The best tour is the pair with the highest ratings and the least walking.

Step-by-Step Execution Trace Table

Trace of Example 1: values = [8, 1, 5, 2, 6]. best_left = 8 (spot 0, 8 + 0) and best = -inf.

jvalues[j]best = max(best, best_left + values[j] - j)best_left = max(best_left, values[j] + j)
11max(-inf, 8 + 1 - 1) = 8max(8, 1 + 1) = 8
25max(8, 8 + 5 - 2) = 11max(8, 5 + 2) = 8
32max(11, 8 + 2 - 3) = 11max(8, 2 + 3) = 8
46max(11, 8 + 6 - 4) = 11max(8, 6 + 4) = 10

At j = 2, the best earlier spot is spot 0, so the score is 11. At j = 4, best_left is still 8, because best_left is updated with spot 4 only after spot 4 is scored.

Code Shape
Archetype Code Shape
Python
1best_left = values[0]; best = float('-inf')
2for j in range(1, len(values)):
3 best = max(best, best_left + values[j] - j)
4 best_left = max(best_left, values[j] + j)
5return best

Conceptual Narrative

🧭 Conceptual Foundation & Pattern Intuition

A pair of spots i < j has the score values[i] + values[j] + i - j. Trying every pair takes N * (N - 1) / 2 checks. The score can be regrouped as (values[i] + i) + (values[j] - j). The first part needs only i. The second part needs only j.

➗ What Is Carried From The Left

For one right end j, the second part is fixed. The best score for j uses the earlier spot with the largest values[i] + i. One variable, best_left, keeps that largest value. It is the whole state of the DP.

🔑 The Key Idea in the Code

The loop scores j first and updates best_left with j second. If the order is reversed, best_left already contains spot j, and the spot is paired with itself.

  • Updating best_left with spot j before scoring j: best_left then contains spot j, and the pair uses the same spot twice. [8, 1, 5, 2, 6] returns 12 instead of 11.

  • Carrying values[i] instead of values[i] + i: the distance is part of the left term. [1, 1, 1, 1, 9] returns 6 instead of 9.

  • Leaving out - j from the score: the distance is never subtracted. [8, 1, 5, 2, 6] returns 14 instead of 11.

  • Starting the loop at j = 0: spot 0 is scored against itself. [8, 1, 5, 2, 6] returns 16 instead of 11.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

"Maximum score of a pair of spots" with the score values[i] + values[j] + i - j: the pair must be in order (i < j), and the score adds a term for i and a term for j. When a pair score separates into one term for each end, the best left end can be carried while the loop moves right.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Before spot j is scored, best_left is the largest values[i] + i over all spots i < j, and best is the largest score of any pair that ends before j. The score of j is best_left + values[j] - j.

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 the best left half carry. The score values i plus values j plus i minus j can be regrouped as values i plus i, plus values j minus j. The first part needs only the left spot and the second part needs only the right spot. So for each right spot j, the best partner is the earlier spot with the largest values i plus i. I keep that in one variable, best left, which starts as the first spot. For each j from one on, I first score the pair, best left plus values j minus j, and keep the maximum. Only after that, I update best left with values j plus j. If I updated first, j would pair with itself. 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 j in range(1, len(values)) visits each spot after the first once. Each visit does one max to score j and one max to update best_left, which is constant work. That is N - 1 steps, so time is O(N).

SPACE COMPLEXITY

O(1)

The code keeps two variables, best_left and best, whatever the length of values is. There is no table and no recursion, so space is O(1).

Formal Recurrence Relation

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

Derivation Progression

Passes

N−1 spotsN - 1 \text{ spots}N−1 spots

for j in range(1, len(values)) visits each spot after the first once.

Work per spot

2 = O(1)

One max for best and one max for best_left.

Total

2(N - 1) = O(N)

Spots times a constant amount of work.

Variable Definitions

NNN

Length of values

bestleftbest_leftbestl​eft

Largest values[i] + i over the spots before j

bestbestbest

Largest pair score found so far

Memory Architecture & Bounds

🟣 Call Stack

O(1): a loop only, no recursion

🔵 Auxiliary Heap

O(1): the variables best_left 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 spot.

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 score of a pair of spots", "i < j". A pair score that adds a term for each end and subtracts the distance can be regrouped into a left part and a right part, so the best left end is carried while the loop moves right.

CONSTRAINTS & BOUNDS

N≤5×104N \le 5 \times 10^4N≤5×104 and 1≤values[i]≤10001 \le values[i] \le 10001≤values[i]≤1000. Scoring every pair is about 1.25×1091.25 \times 10^91.25×109 pairs in the worst case, which is too slow. One pass is O(N)O(N)O(N). The carried value values[i] + i is at most about 5×1045 \times 10^45×104, so 32-bit integers are enough.

FAANG PRODUCTION TRAPS & EDGE CASES

Updating best_left before scoring j pairs j with itself, and [8, 1, 5, 2, 6] returns 12 instead of 11. Starting the loop at j = 0 does the same with spot 0. best starts at minus infinity so that the first real score replaces it.

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