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 300

Longest Increasing Subsequence (LeetCode 300)

Target Frequency:MetaAppleAmazon

You're given an integer array nums. Deleting any subset of its elements (possibly none) while keeping the rest in their original order produces a subsequence.

Find the length of the longest subsequence you can produce this way whose values keep strictly increasing from left to right.

Worked Examples

Example 1
Input:nums = [10,9,2,5,3,7,101,18]
Output:4
Explanation: The longest increasing subsequence is [2,3,7,101], therefore the length is 4.
Example 2
Input:nums = [0,1,0,3,2,3]
Output:4
Explanation: 0, 1, 2, 3 is strictly increasing and has length 4.
Example 3
Input:nums = [7,7,7,7,7,7,7]
Output:1
Explanation: All values are equal, so an increasing subsequence can hold only one of them.

⚖️Formal Constraints & Bounds

  • 1 <= nums.length <= 2500

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

Deep-Dive & Conceptual Insights

Core Insight

For every length, keep only the smallest value an increasing subsequence of that length can end with; each new number replaces the first such tail that is not smaller than it, or extends the list, so the list length is the answer.

Real-World Scenario & Production Applications

Version control DAG(Directed Acyclic Graph) sequence alignment, tournament streak tracking.

Subproblems & Recurrence Decomposition3 Phases

🧩Subproblem 1: One Tail per Length

tails[k] is the smallest value that can end an increasing subsequence of length k + 1 among the numbers read so far. It starts empty, and it stays sorted.

Mathematical Recurrence / Code Invariant
tails = []

Step-by-Step Execution Trace Table

xbisect_left(tails, x)Actiontails after
100append[10]
90replace 10[9]
20replace 9[2]
51append[2, 5]
31replace 5[2, 3]
72append[2, 3, 7]
1013append[2, 3, 7, 101]
183replace 101[2, 3, 7, 18] → 4
Code Shape
Archetype Code Shape
Python
1tails = []
2for x in nums:
3 idx = bisect_left(tails, x)
4idx == len(tails) ? tails.append(x) : tails[idx] = x
5return len(tails)

Conceptual Narrative

🧭 Conceptual Foundation & Pattern Intuition
Code / Blueprint
Finding the length of the longest strictly increasing subsequence can be solved in $O(N^2)$ via quadratic DP or in $O(N \log N)$ via Patience Sorting. We maintain an array `tails` where `tails[i]` stores the smallest tail element among all valid subsequences of length $i + 1$. For each number $x$, binary search (`bisect_left`) finds the first tail $\ge x$ and replaces it. If $x$ is larger than all tails, it appends to `tails`, increasing the maximum subsequence length.
 
🃏 The Analogy: Dealing Cards onto Piles

Deal the numbers left to right as cards. Each card goes on the leftmost pile whose top card is at least as big as it; if no pile qualifies, it starts a new pile on the right. The pile tops, read left to right, always climb, and the number of piles is the length of the longest increasing subsequence. tails is exactly the row of pile tops.

🔑 The Key Idea in the Code

The answer is len(tails), not tails itself: after [3, 4, 1] the tops are [1, 4], which is not a subsequence of the input, even though the length 2 is right.

  • Strictly increasing vs non-decreasing: Using nums[j] <= nums[i] instead of nums[j] < nums[i]. The problem specifies strictly increasing; duplicate values cannot extend the subsequence.

  • Assuming the answer is dp[-1]: The LIS does not necessarily end at the last element of the array; the global maximum can end anywhere. The result must be max(dp).

  • Defaulting to O(N2)O(N^2)O(N2) when O(Nlog⁡N)O(N \log N)O(NlogN) is expected: For N=105N = 10^5N=105, O(N2)O(N^2)O(N2) DP gets TLE. Use patience sorting with binary search (bisect_left on a tails array).

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

Longest strictly increasing subsequence over arbitrary jump distances.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Invariant: tails is sorted, and tails[k] is the smallest last value of any increasing subsequence of length k + 1 seen so far.

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

  • Reading tails as the answer: it has the right length but is usually not a real subsequence of nums, so store each element's predecessor index if you must rebuild the sequence.

  • Using bisect_right instead of bisect_left: an equal value would then be appended and counted as increasing, so [7, 7, 7, 7, 7] would return 5 instead of 1.

The 60-Second Interview Pitch

Say this out loud before you type a single line

"I'd use the LIS tails trick. I keep tails[k], the smallest last value of any increasing run of length k + 1 seen so far. For each number I binary-search the first tail that is at least it. If there is none, the number extends the longest run and I append it; otherwise I replace that tail with it. A smaller tail can only help, because it leaves more room for the numbers that come later, and replacing keeps tails sorted, so its length is always the longest length so far. Searching for the first tail that is at least the number, not greater than it, keeps the runs strictly increasing. The trap is reading tails as the answer: it has the right length but is usually not a real subsequence, so I store predecessors if I must rebuild it. N binary searches give O(N log N) time and O(N) space."

Big-O Invariant Derivation

Complexity & Mathematical Proof

TIME COMPLEXITY

O(N log N)

Look at the execution steps: Maintains tails array where tails[i] is the smallest tail of all increasing subsequences of length i+1. Binary search finds insertion position in tails in O(log N) per element. Total N * log N.

SPACE COMPLEXITY

O(N) Auxiliary

Look at memory allocations: Call stack uses O(1) Iterative. tails array of length at most N.

Formal Recurrence Relation

T(N) = N · O(log N) = O(N log N)

Derivation Progression

Tails Array Invariant

tails[i] < tails[i+1]

tails array is strictly sorted, enabling binary search.

Binary Search Insertion

O(log(len(tails))) per element

Replaces earliest tail >= x or extends tails if x is strictly larger.

Total Time

N × O(log N) = O(N log N)

Optimal time for LIS length.

Variable Definitions

NNN

Total number of elements in the array

Memory Architecture & Bounds

🟣 Call Stack

O(1) Iterative

🔵 Auxiliary Heap

O(N) tails array

🟢 Output Space

O(1) LIS length integer

Boundary Best / Worst Cases

Best Case

O(Nlog⁡N)O(N \log N)O(NlogN)

Average Case

O(Nlog⁡N)O(N \log N)O(NlogN)

Worst Case

O(Nlog⁡N)O(N \log N)O(NlogN)

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: "longest strictly increasing subsequence". While O(N2)O(N^2)O(N2) coordinate DP tabulates dp[i]=1+max⁡(dp[j] for j<i and nums[j]<nums[i])dp[i] = 1 + \max(dp[j] \text{ for } j < i \text{ and } nums[j] < nums[i])dp[i]=1+max(dp[j] for j<i and nums[j]<nums[i]), an experienced engineer utilizes Patience Sorting with Binary Search to solve this in O(Nlog⁡N)O(N \log N)O(NlogN)!

CONSTRAINTS & BOUNDS

N≤2500N \le 2500N≤2500. O(Nlog⁡N)O(N \log N)O(NlogN) runs in <10< 10<10ms.

FAANG PRODUCTION TRAPS & EDGE CASES

Streams: each value costs one binary search, and tails never grows longer than the answer itself, so the loop runs on a stream of values that never fits in memory, as long as only the length is needed.

Theory Context•Dynamic Programming
MediumLC 300

Longest Increasing Subsequence (LeetCode 300)

Target Frequency:MetaAppleAmazon

You're given an integer array nums. Deleting any subset of its elements (possibly none) while keeping the rest in their original order produces a subsequence.

Find the length of the longest subsequence you can produce this way whose values keep strictly increasing from left to right.

Worked Examples

Example 1
Input:nums = [10,9,2,5,3,7,101,18]
Output:4
Explanation: The longest increasing subsequence is [2,3,7,101], therefore the length is 4.
Example 2
Input:nums = [0,1,0,3,2,3]
Output:4
Explanation: 0, 1, 2, 3 is strictly increasing and has length 4.
Example 3
Input:nums = [7,7,7,7,7,7,7]
Output:1
Explanation: All values are equal, so an increasing subsequence can hold only one of them.

⚖️Formal Constraints & Bounds

  • 1 <= nums.length <= 2500

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

Deep-Dive & Conceptual Insights

Core Insight

For every length, keep only the smallest value an increasing subsequence of that length can end with; each new number replaces the first such tail that is not smaller than it, or extends the list, so the list length is the answer.

Real-World Scenario & Production Applications

Version control DAG(Directed Acyclic Graph) sequence alignment, tournament streak tracking.

Subproblems & Recurrence Decomposition3 Phases

🧩Subproblem 1: One Tail per Length

tails[k] is the smallest value that can end an increasing subsequence of length k + 1 among the numbers read so far. It starts empty, and it stays sorted.

Mathematical Recurrence / Code Invariant
tails = []

Step-by-Step Execution Trace Table

xbisect_left(tails, x)Actiontails after
100append[10]
90replace 10[9]
20replace 9[2]
51append[2, 5]
31replace 5[2, 3]
72append[2, 3, 7]
1013append[2, 3, 7, 101]
183replace 101[2, 3, 7, 18] → 4
Code Shape
Archetype Code Shape
Python
1tails = []
2for x in nums:
3 idx = bisect_left(tails, x)
4idx == len(tails) ? tails.append(x) : tails[idx] = x
5return len(tails)

Conceptual Narrative

🧭 Conceptual Foundation & Pattern Intuition
Code / Blueprint
Finding the length of the longest strictly increasing subsequence can be solved in $O(N^2)$ via quadratic DP or in $O(N \log N)$ via Patience Sorting. We maintain an array `tails` where `tails[i]` stores the smallest tail element among all valid subsequences of length $i + 1$. For each number $x$, binary search (`bisect_left`) finds the first tail $\ge x$ and replaces it. If $x$ is larger than all tails, it appends to `tails`, increasing the maximum subsequence length.
 
🃏 The Analogy: Dealing Cards onto Piles

Deal the numbers left to right as cards. Each card goes on the leftmost pile whose top card is at least as big as it; if no pile qualifies, it starts a new pile on the right. The pile tops, read left to right, always climb, and the number of piles is the length of the longest increasing subsequence. tails is exactly the row of pile tops.

🔑 The Key Idea in the Code

The answer is len(tails), not tails itself: after [3, 4, 1] the tops are [1, 4], which is not a subsequence of the input, even though the length 2 is right.

  • Strictly increasing vs non-decreasing: Using nums[j] <= nums[i] instead of nums[j] < nums[i]. The problem specifies strictly increasing; duplicate values cannot extend the subsequence.

  • Assuming the answer is dp[-1]: The LIS does not necessarily end at the last element of the array; the global maximum can end anywhere. The result must be max(dp).

  • Defaulting to O(N2)O(N^2)O(N2) when O(Nlog⁡N)O(N \log N)O(NlogN) is expected: For N=105N = 10^5N=105, O(N2)O(N^2)O(N2) DP gets TLE. Use patience sorting with binary search (bisect_left on a tails array).

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

Longest strictly increasing subsequence over arbitrary jump distances.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Invariant: tails is sorted, and tails[k] is the smallest last value of any increasing subsequence of length k + 1 seen so far.

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

  • Reading tails as the answer: it has the right length but is usually not a real subsequence of nums, so store each element's predecessor index if you must rebuild the sequence.

  • Using bisect_right instead of bisect_left: an equal value would then be appended and counted as increasing, so [7, 7, 7, 7, 7] would return 5 instead of 1.

The 60-Second Interview Pitch

Say this out loud before you type a single line

"I'd use the LIS tails trick. I keep tails[k], the smallest last value of any increasing run of length k + 1 seen so far. For each number I binary-search the first tail that is at least it. If there is none, the number extends the longest run and I append it; otherwise I replace that tail with it. A smaller tail can only help, because it leaves more room for the numbers that come later, and replacing keeps tails sorted, so its length is always the longest length so far. Searching for the first tail that is at least the number, not greater than it, keeps the runs strictly increasing. The trap is reading tails as the answer: it has the right length but is usually not a real subsequence, so I store predecessors if I must rebuild it. N binary searches give O(N log N) time and O(N) space."

Big-O Invariant Derivation

Complexity & Mathematical Proof

TIME COMPLEXITY

O(N log N)

Look at the execution steps: Maintains tails array where tails[i] is the smallest tail of all increasing subsequences of length i+1. Binary search finds insertion position in tails in O(log N) per element. Total N * log N.

SPACE COMPLEXITY

O(N) Auxiliary

Look at memory allocations: Call stack uses O(1) Iterative. tails array of length at most N.

Formal Recurrence Relation

T(N) = N · O(log N) = O(N log N)

Derivation Progression

Tails Array Invariant

tails[i] < tails[i+1]

tails array is strictly sorted, enabling binary search.

Binary Search Insertion

O(log(len(tails))) per element

Replaces earliest tail >= x or extends tails if x is strictly larger.

Total Time

N × O(log N) = O(N log N)

Optimal time for LIS length.

Variable Definitions

NNN

Total number of elements in the array

Memory Architecture & Bounds

🟣 Call Stack

O(1) Iterative

🔵 Auxiliary Heap

O(N) tails array

🟢 Output Space

O(1) LIS length integer

Boundary Best / Worst Cases

Best Case

O(Nlog⁡N)O(N \log N)O(NlogN)

Average Case

O(Nlog⁡N)O(N \log N)O(NlogN)

Worst Case

O(Nlog⁡N)O(N \log N)O(NlogN)

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: "longest strictly increasing subsequence". While O(N2)O(N^2)O(N2) coordinate DP tabulates dp[i]=1+max⁡(dp[j] for j<i and nums[j]<nums[i])dp[i] = 1 + \max(dp[j] \text{ for } j < i \text{ and } nums[j] < nums[i])dp[i]=1+max(dp[j] for j<i and nums[j]<nums[i]), an experienced engineer utilizes Patience Sorting with Binary Search to solve this in O(Nlog⁡N)O(N \log N)O(NlogN)!

CONSTRAINTS & BOUNDS

N≤2500N \le 2500N≤2500. O(Nlog⁡N)O(N \log N)O(NlogN) runs in <10< 10<10ms.

FAANG PRODUCTION TRAPS & EDGE CASES

Streams: each value costs one binary search, and tails never grows longer than the answer itself, so the loop runs on a stream of values that never fits in memory, as long as only the length is needed.

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