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•Binary Search Boundary
EasyLC 704

Binary Search (LC 704)

Target Frequency:GoogleAmazonMicrosoft

nums is an integer array sorted in ascending order, and target is an integer; find where target sits in nums. Return that index if target is present, or -1 if it isn't.

Your algorithm must run in O(log n) time.

Worked Examples

Example 1
Input:nums = [-1,0,3,5,9,12], target = 9
Output:4
Explanation: 9 exists in nums and its index is 4
Example 2
Input:nums = [-1,0,3,5,9,12], target = 2
Output:-1
Explanation: 2 does not exist in nums so return -1

⚖️Formal Constraints & Bounds

  • 1 <= nums.length <= 104

  • -104 < nums[i], target < 104

  • All the integers in nums are unique.

  • nums is sorted in ascending order.

Deep-Dive & Conceptual Insights

Core Insight

If target is in the sorted list, it is at the first index whose value is at least target. Lower Bound finds that index. One look at it answers the question.

Real-World Scenario & Production Applications

When looking up a record in an indexed B-Tree in PostgreSQL or searching an in-memory sorted cache, you never scan sequentially from the beginning. You jump to the middle, determine whether your key comes alphabetically or numerically before or after, and discard half the data space in a single CPU cycle.

Subproblems & Recurrence Decomposition3 Phases

🧩Subproblem 1: The Check And The Range

Ask each index one yes-or-no question: nums[i] >= target. The answers are False before target's position and True from it on. Use the range [lo, hi) = [0, len(nums)), so len(nums) stays a possible answer.

Mathematical Recurrence / Code Invariant
# Check: False before target's position, True from it on
def at_least_target(i):
    return nums[i] >= target
lo, hi = 0, len(nums)

Step-by-Step Execution Trace Table

StepRange [lo, hi)midnums[mid]Check nums[mid] >= 9DecisionNew range [lo, hi)
1[0, 6)35False5 is smaller than 9, so the first True is after mid: lo = mid + 1[4, 6)
2[4, 6)512Truemid may be the first True, so keep it: hi = mid[4, 5)
3[4, 5)49Truemid may be the first True, so keep it: hi = mid[4, 4)
4[4, 4)The range is empty. Lower Bound returns i = 4.
Looknums[4] is 94 < len(nums) and nums[4] == 9Return index 4
Code Shape
Archetype Code Shape
Python
1def at_least_target(i):
2 return nums[i] >= target
3lo = 0
4hi = len(nums)
5i = binary_search_lower_bound(lo, hi, at_least_target)
6if i < len(nums) and nums[i] == target:
7 return i
8return -1

Conceptual Narrative

🧭 Conceptual Foundation & Pattern Intuition

Exact Match asks whether a key is in a sorted list, and at which index. The answer is one look after a Lower Bound search. If the key is in the list, it sits at the first index whose value is at least the key. So find that index, and look at it.

🏟️ The Analogy: Opening an Alphabetized Physical Dictionary

Imagine looking up the word "Quasar" in a physical 2,000-page dictionary. You don't start at page 1 and read every word. You open the book roughly in the middle, landing on the letter "M". Since "Q" comes after "M", you instantly disregard pages 1 through 1,000 with your left hand. You then split the remaining pages 1,001 through 2,000 in half, landing on "T". Since "Q" comes before "T", you disregard pages 1,500 through 2,000. Each physical split discards hundreds of pages in constant time.

🔑 Why It Works

Every index before the first True holds a value smaller than the key, and the first True holds a value that is at least the key. If that value is equal to the key, it is the first copy. If it is larger, the key is not in the list. When every value is smaller, Lower Bound returns len(nums), and there is nothing to read, so the check i < len(nums) comes first.`,

  • Reading nums[i] without checking i < len(nums): Lower Bound returns len(nums) when every value is smaller than target. There is no value at that index, so nums[i] raises an IndexError.

  • Using nums[i] == target as the check: Lower Bound needs a row that reads False…False True…True. The row of nums[i] == target is True at one index only.

  • Expecting any copy of target: the template returns the first copy. The older closed-range loop returns the copy that it reaches first.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

You are given a sorted list and need the index of one value, or a sign that it is missing. The problem asks for better than O(N) time, so each step must remove half of the candidates.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Invariant: if target is in nums, it is at the first index whose value is at least target. The check nums[i] >= target is False for every index before that position and True from it on, so Lower Bound can find it. One look at that index then tells whether target is there.

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 use Exact Match. The array is sorted, so the check nums[i] >= target is False before target's position and True from it on. I run Lower Bound over [0, len(nums)) with that check, and it returns the first index whose value is at least target. Then I look at that one index. If i < len(nums) and nums[i] == target, I return i. Otherwise I return -1. The trap is reading nums[i] when i equals len(nums), so I check the bound first. Lower Bound halves the range on every pass, so the time is O(log n), and the space is O(1)."

Big-O Invariant Derivation

Complexity & Mathematical Proof

TIME COMPLEXITY

O(log N)

Look at the loop in Lower Bound: while lo < hi:. Each pass computes mid and evaluates nums[mid] >= target in O(1). Then it keeps [lo, mid) or [mid + 1, hi), so the range loses at least half of its candidates. At most floor(log2 N) + 1 passes run (see the stages below). The final look at nums[i] is one comparison, so the total is O(log N) time.

SPACE COMPLEXITY

O(1)

Look at the memory used: the loop is iterative, so the call stack holds one frame. Inside the function we store only the integers lo, hi, mid and i. We allocate no extra arrays, hash tables, or objects. Auxiliary space is O(1).

Formal Recurrence Relation

T(N)=T(N/2)+O(1)⟹O(log⁡N)T(N) = T(N/2) + O(1) ⟹ O(\log N)T(N)=T(N/2)+O(1)⟹O(logN)

Derivation Progression

Search Interval Halving

Window Size: N ⟹ N/2 ⟹ N/4 ⟹ ... ⟹ 1

The loop begins with a range of N candidates. Testing nums[mid] >= target removes half of the remaining candidates on every pass.

Constant Work Per Step

O(1) arithmetic + comparison

Calculating mid = lo + (hi - lo) // 2 and reading nums[mid] takes O(1) time, with no inner loop.

Logarithmic Termination

Total Steps = floor(log2 N) + 1 ⟹ O(log N)

Dividing N by 2 repeatedly reaches window width <= 1 in at most floor(log2 N) + 1 iterations.

Variable Definitions

NNN

Total number of elements in the sorted array

Memory Architecture & Bounds

🟣 Call Stack

O(1) Iterative while loop with zero recursion frames

🔵 Auxiliary Heap

O(1) Only scalar pointers (lo, hi, mid) in CPU registers

🟢 Output Space

O(1) Returns a single integer index

Boundary Best / Worst Cases

Best Case

O(log⁡N)O(\log N)O(logN) — Lower Bound does not stop when it meets target, so even the best case runs every halving pass.

Average Case

O(log⁡N)O(\log N)O(logN) — Search requires approximately log⁡2N−1\log_2 N - 1log2​N−1 comparisons.

Worst Case

O(log⁡N)O(\log N)O(logN) — Target is at the boundary leaf index or absent from the array.

Recurrence Tree Topology

Recurrence Tree Topology
Synthesizing vector architecture diagram...
Staff+ Engineering Perspective

Senior SWE Deconstruction & Hardware Caveats

ARCHITECTURAL SIGNALS & INTERVIEW TRIGGERS

When I scan this problem statement, the immediate dead giveaways are the phrases "sorted in ascending order" and the explicit constraint the solution has to run in O(log n) time. A sorted array with unique elements where we are asked to find the index of a single target value is the canonical trigger for Exact Match. It tells me this is not a boundary or answer-space problem on its own. It is Lower Bound plus one look: the check nums[i] >= target is False before target's position and True from it on, so Lower Bound finds where target would go, and one look at that index tells me whether it is there.

CONSTRAINTS & BOUNDS

The array length N≤104N \le 10^4N≤104 means an O(N)O(N)O(N) linear scan would technically execute in a fraction of a millisecond on modern hardware, but the problem's explicit mandate for O(log⁡N)O(\log N)O(logN) strictly disqualifies linear traversal. The values span [−104,104][-10^4, 10^4][−104,104], fitting comfortably inside standard 32-bit signed integers. Because target could be larger than every value, Lower Bound can return len(nums), so the search range is lo = 0 and hi = len(nums), and len(nums) must stay a possible answer.

FAANG PRODUCTION TRAPS & EDGE CASES

The card's trap is reading nums[i] when i == len(nums): when every value is smaller than target, Lower Bound returns len(nums), and Python raises an IndexError. Check i < len(nums) before the look. At scale there is one more: the search is only as correct as the sort. If another thread inserts into or deletes from nums while you search, lo and hi can step past the target, so search a snapshot or hold a read lock.

Theory Context•Binary Search Boundary
EasyLC 704

Binary Search (LC 704)

Target Frequency:GoogleAmazonMicrosoft

nums is an integer array sorted in ascending order, and target is an integer; find where target sits in nums. Return that index if target is present, or -1 if it isn't.

Your algorithm must run in O(log n) time.

Worked Examples

Example 1
Input:nums = [-1,0,3,5,9,12], target = 9
Output:4
Explanation: 9 exists in nums and its index is 4
Example 2
Input:nums = [-1,0,3,5,9,12], target = 2
Output:-1
Explanation: 2 does not exist in nums so return -1

⚖️Formal Constraints & Bounds

  • 1 <= nums.length <= 104

  • -104 < nums[i], target < 104

  • All the integers in nums are unique.

  • nums is sorted in ascending order.

Deep-Dive & Conceptual Insights

Core Insight

If target is in the sorted list, it is at the first index whose value is at least target. Lower Bound finds that index. One look at it answers the question.

Real-World Scenario & Production Applications

When looking up a record in an indexed B-Tree in PostgreSQL or searching an in-memory sorted cache, you never scan sequentially from the beginning. You jump to the middle, determine whether your key comes alphabetically or numerically before or after, and discard half the data space in a single CPU cycle.

Subproblems & Recurrence Decomposition3 Phases

🧩Subproblem 1: The Check And The Range

Ask each index one yes-or-no question: nums[i] >= target. The answers are False before target's position and True from it on. Use the range [lo, hi) = [0, len(nums)), so len(nums) stays a possible answer.

Mathematical Recurrence / Code Invariant
# Check: False before target's position, True from it on
def at_least_target(i):
    return nums[i] >= target
lo, hi = 0, len(nums)

Step-by-Step Execution Trace Table

StepRange [lo, hi)midnums[mid]Check nums[mid] >= 9DecisionNew range [lo, hi)
1[0, 6)35False5 is smaller than 9, so the first True is after mid: lo = mid + 1[4, 6)
2[4, 6)512Truemid may be the first True, so keep it: hi = mid[4, 5)
3[4, 5)49Truemid may be the first True, so keep it: hi = mid[4, 4)
4[4, 4)The range is empty. Lower Bound returns i = 4.
Looknums[4] is 94 < len(nums) and nums[4] == 9Return index 4
Code Shape
Archetype Code Shape
Python
1def at_least_target(i):
2 return nums[i] >= target
3lo = 0
4hi = len(nums)
5i = binary_search_lower_bound(lo, hi, at_least_target)
6if i < len(nums) and nums[i] == target:
7 return i
8return -1

Conceptual Narrative

🧭 Conceptual Foundation & Pattern Intuition

Exact Match asks whether a key is in a sorted list, and at which index. The answer is one look after a Lower Bound search. If the key is in the list, it sits at the first index whose value is at least the key. So find that index, and look at it.

🏟️ The Analogy: Opening an Alphabetized Physical Dictionary

Imagine looking up the word "Quasar" in a physical 2,000-page dictionary. You don't start at page 1 and read every word. You open the book roughly in the middle, landing on the letter "M". Since "Q" comes after "M", you instantly disregard pages 1 through 1,000 with your left hand. You then split the remaining pages 1,001 through 2,000 in half, landing on "T". Since "Q" comes before "T", you disregard pages 1,500 through 2,000. Each physical split discards hundreds of pages in constant time.

🔑 Why It Works

Every index before the first True holds a value smaller than the key, and the first True holds a value that is at least the key. If that value is equal to the key, it is the first copy. If it is larger, the key is not in the list. When every value is smaller, Lower Bound returns len(nums), and there is nothing to read, so the check i < len(nums) comes first.`,

  • Reading nums[i] without checking i < len(nums): Lower Bound returns len(nums) when every value is smaller than target. There is no value at that index, so nums[i] raises an IndexError.

  • Using nums[i] == target as the check: Lower Bound needs a row that reads False…False True…True. The row of nums[i] == target is True at one index only.

  • Expecting any copy of target: the template returns the first copy. The older closed-range loop returns the copy that it reaches first.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

You are given a sorted list and need the index of one value, or a sign that it is missing. The problem asks for better than O(N) time, so each step must remove half of the candidates.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Invariant: if target is in nums, it is at the first index whose value is at least target. The check nums[i] >= target is False for every index before that position and True from it on, so Lower Bound can find it. One look at that index then tells whether target is there.

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 use Exact Match. The array is sorted, so the check nums[i] >= target is False before target's position and True from it on. I run Lower Bound over [0, len(nums)) with that check, and it returns the first index whose value is at least target. Then I look at that one index. If i < len(nums) and nums[i] == target, I return i. Otherwise I return -1. The trap is reading nums[i] when i equals len(nums), so I check the bound first. Lower Bound halves the range on every pass, so the time is O(log n), and the space is O(1)."

Big-O Invariant Derivation

Complexity & Mathematical Proof

TIME COMPLEXITY

O(log N)

Look at the loop in Lower Bound: while lo < hi:. Each pass computes mid and evaluates nums[mid] >= target in O(1). Then it keeps [lo, mid) or [mid + 1, hi), so the range loses at least half of its candidates. At most floor(log2 N) + 1 passes run (see the stages below). The final look at nums[i] is one comparison, so the total is O(log N) time.

SPACE COMPLEXITY

O(1)

Look at the memory used: the loop is iterative, so the call stack holds one frame. Inside the function we store only the integers lo, hi, mid and i. We allocate no extra arrays, hash tables, or objects. Auxiliary space is O(1).

Formal Recurrence Relation

T(N)=T(N/2)+O(1)⟹O(log⁡N)T(N) = T(N/2) + O(1) ⟹ O(\log N)T(N)=T(N/2)+O(1)⟹O(logN)

Derivation Progression

Search Interval Halving

Window Size: N ⟹ N/2 ⟹ N/4 ⟹ ... ⟹ 1

The loop begins with a range of N candidates. Testing nums[mid] >= target removes half of the remaining candidates on every pass.

Constant Work Per Step

O(1) arithmetic + comparison

Calculating mid = lo + (hi - lo) // 2 and reading nums[mid] takes O(1) time, with no inner loop.

Logarithmic Termination

Total Steps = floor(log2 N) + 1 ⟹ O(log N)

Dividing N by 2 repeatedly reaches window width <= 1 in at most floor(log2 N) + 1 iterations.

Variable Definitions

NNN

Total number of elements in the sorted array

Memory Architecture & Bounds

🟣 Call Stack

O(1) Iterative while loop with zero recursion frames

🔵 Auxiliary Heap

O(1) Only scalar pointers (lo, hi, mid) in CPU registers

🟢 Output Space

O(1) Returns a single integer index

Boundary Best / Worst Cases

Best Case

O(log⁡N)O(\log N)O(logN) — Lower Bound does not stop when it meets target, so even the best case runs every halving pass.

Average Case

O(log⁡N)O(\log N)O(logN) — Search requires approximately log⁡2N−1\log_2 N - 1log2​N−1 comparisons.

Worst Case

O(log⁡N)O(\log N)O(logN) — Target is at the boundary leaf index or absent from the array.

Recurrence Tree Topology

Recurrence Tree Topology
Synthesizing vector architecture diagram...
Staff+ Engineering Perspective

Senior SWE Deconstruction & Hardware Caveats

ARCHITECTURAL SIGNALS & INTERVIEW TRIGGERS

When I scan this problem statement, the immediate dead giveaways are the phrases "sorted in ascending order" and the explicit constraint the solution has to run in O(log n) time. A sorted array with unique elements where we are asked to find the index of a single target value is the canonical trigger for Exact Match. It tells me this is not a boundary or answer-space problem on its own. It is Lower Bound plus one look: the check nums[i] >= target is False before target's position and True from it on, so Lower Bound finds where target would go, and one look at that index tells me whether it is there.

CONSTRAINTS & BOUNDS

The array length N≤104N \le 10^4N≤104 means an O(N)O(N)O(N) linear scan would technically execute in a fraction of a millisecond on modern hardware, but the problem's explicit mandate for O(log⁡N)O(\log N)O(logN) strictly disqualifies linear traversal. The values span [−104,104][-10^4, 10^4][−104,104], fitting comfortably inside standard 32-bit signed integers. Because target could be larger than every value, Lower Bound can return len(nums), so the search range is lo = 0 and hi = len(nums), and len(nums) must stay a possible answer.

FAANG PRODUCTION TRAPS & EDGE CASES

The card's trap is reading nums[i] when i == len(nums): when every value is smaller than target, Lower Bound returns len(nums), and Python raises an IndexError. Check i < len(nums) before the look. At scale there is one more: the search is only as correct as the sort. If another thread inserts into or deletes from nums while you search, lo and hi can step past the target, so search a snapshot or hold a read lock.

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