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•Depth-First Search (DFS)
EasyLC 110

Balanced Binary Tree (LeetCode 110)

Target Frequency:AmazonGoogleMeta

You're given a binary tree and need to decide whether it counts as height-balanced.

A tree earns that label when, at every single node, the heights of its left and right subtrees never disagree by more than one.

Worked Examples

Example 1
Input:root = [3,9,20,null,null,15,7]
Output:true
9315207
Explanation: At every node the left and right subtrees differ in height by at most one.
Example 2
Input:root = [1,2,2,3,3,null,null,4,4]
Output:false
4342312
Explanation: The root's left side is 3 levels deep but its right side only 1, a difference of 2.
Example 3
Input:root = []
Output:true
Explanation: An empty tree counts as balanced.

⚖️Formal Constraints & Bounds

  • The number of nodes in the tree is in the range [0, 5000].

  • -104 <= Node.val <= 104

Deep-Dive & Conceptual Insights

Core Insight

Returning -1 from subtrees allows instant failure propagation without computing full tree depths.

Real-World Scenario & Production Applications

Self-balancing AVL/Red-Black tree rebalancing triggers, database index tree verification.

Step-by-Step Execution Trace Table

NodeLeft HeightRight HeightDifferenceStatus
15 (leaf)000Balanced (h=1)
7 (leaf)000Balanced (h=1)
20110Balanced (h=2)
9 (leaf)000Balanced (h=1)
3 (root)121Balanced (h=3)
Trace Inputroot = [3,9,20,null,null,15,7]
Expectedtrue
NodeLeft HeightRight HeightDifferenceStatus
15 (leaf)000Balanced (h=1)
7 (leaf)000Balanced (h=1)
20110Balanced (h=2)
9 (leaf)000Balanced (h=1)
3 (root)121Balanced (h=3)
Code Shape
Archetype Code Shape
Python
1def check_height(node):
2 if not node:
3 return 0
4 left, right = check_height(node.left), check_height(node.right)
5 if left == -1 or right == -1 or abs(left - right) > 1:
6 return -1
7 return max(left, right) + 1
8return check_height(root) != -1

Conceptual Narrative

🧭 Conceptual Foundation & Pattern Intuition

The obvious approach — compute each subtree's height, then separately check balance at each node — re-walks the same subtrees over and over. This trick answers both questions in a single pass by hijacking the return value.

🏗️ The Analogy: A Building Inspector Who Stops at the First Crack

Imagine a building inspector checking a tower floor by floor, from the top down conceptually, but reporting bottom-up. At each floor, they want to report how tall the tower is above this point — but if they ever discover a structural imbalance below, there's no point continuing to measure heights accurately; they just need to report "unsafe" all the way up to whoever's asking, instantly, without finishing the inspection.

🔑 The Key Idea in the Code

-1 is overloaded to mean two different things depending on context: "not yet checked" becomes "structurally broken, stop caring about the real number." Once any subtree reports -1, every ancestor just relays -1 straight up without doing any more work — a free early exit riding on the same recursive call that computes height.

  • Quadratic O(N2)O(N^2)O(N2) top-down traversal: Calling height(node.left) and height(node.right) at each level recomputes subtree depths redundantly. A bottom-up DFS returning -1 on imbalance computes balance in O(N)O(N)O(N) time.

  • Missing sentinel early-exit propagation: When a child subtree returns -1 (unbalanced), the parent must immediately propagate -1 without computing abs(left - right).

  • Treating difference of 1 as unbalanced: The definition of height-balanced requires abs(left - right) <= 1. Failing when difference equals 1 rejects valid balanced trees.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

Tree height-balance condition + require optimal O(N) single-pass without quadratic depth recalculations.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Invariant: check_height returns actual subtree height if balanced, or -1 if any descendant subtree is unbalanced.

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

  • Forgetting to check if left_h == -1 before checking right subtree.

The 60-Second Interview Pitch

Say this out loud before you type a single line

"I use a bottom-up post-order DFS helper check_height. It returns the height if balanced, or -1 as soon as any subtree is unbalanced. When a child returns -1 or abs(L - R) > 1, it immediately propagates -1 upward. Runs in strict O(N) time and O(H) space."

Big-O Invariant Derivation

Complexity & Mathematical Proof

TIME COMPLEXITY

O(N)

Look at the execution steps: Bottom-up DFS returns tree height or -1 if unbalanced. Any unbalanced subtree short-circuits immediately, visiting each node at most once.

SPACE COMPLEXITY

O(H) Auxiliary

Recursion stack depth equals tree height H.

Formal Recurrence Relation

T(N) = ∑_{v} O(1) = O(N)

Derivation Progression

Bottom-Up Height Compute

H(v) = 1 + max(HL, HR)

Computes height from children in a single post-order traversal.

Early Pruning Sentinel

if |HL - HR| > 1: return -1

Propagates failure upward immediately without redundant visits.

Linear Single Pass

O(N) node visits

Eliminates repeated depth calculations.

Variable Definitions

NNN

Total number of nodes in the binary tree

HHH

Tree height (log N in balanced tree, N in skewed tree)

Memory Architecture & Bounds

🟣 Call Stack

O(H) Call stack (log N <= H <= N)

🔵 Auxiliary Heap

O(1) Zero heap memory

🟢 Output Space

O(1) Boolean balance status

Boundary Best / Worst Cases

Best Case

O(1)O(1)O(1) if root is unbalanced, otherwise O(N)O(N)O(N).

Average Case

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

Worst Case

O(N)O(N)O(N) on balanced tree.

Graph & Tree Traversal Frontier

Graph & Tree Traversal Frontier
Synthesizing vector architecture diagram...
Staff+ Engineering Perspective

Senior SWE Deconstruction & Hardware Caveats

ARCHITECTURAL SIGNALS & INTERVIEW TRIGGERS

Triggers: "height-balanced binary tree", "depth of two subtrees of every node never differs by more than one". Naive top-down calculation computes depth(left) and depth(right) at each node, taking O(N2)O(N^2)O(N2) time. A Senior SWE implements a Bottom-Up Check with Sentinel Early Exit (-1): return actual height if balanced, or -1 if unbalanced to immediately short-circuit up the call stack!

CONSTRAINTS & BOUNDS

N≤5000N \le 5000N≤5000. Time budget is strictly O(N)O(N)O(N) linear time.

FAANG PRODUCTION TRAPS & EDGE CASES

O(N2)O(N^2)O(N2) top-down trap: calling maxDepth inside a separate isBalanced recursive helper causes redundant traversal. The combined height/balance check solves the entire problem in a single post-order pass.

Theory Context•Depth-First Search (DFS)
EasyLC 110

Balanced Binary Tree (LeetCode 110)

Target Frequency:AmazonGoogleMeta

You're given a binary tree and need to decide whether it counts as height-balanced.

A tree earns that label when, at every single node, the heights of its left and right subtrees never disagree by more than one.

Worked Examples

Example 1
Input:root = [3,9,20,null,null,15,7]
Output:true
9315207
Explanation: At every node the left and right subtrees differ in height by at most one.
Example 2
Input:root = [1,2,2,3,3,null,null,4,4]
Output:false
4342312
Explanation: The root's left side is 3 levels deep but its right side only 1, a difference of 2.
Example 3
Input:root = []
Output:true
Explanation: An empty tree counts as balanced.

⚖️Formal Constraints & Bounds

  • The number of nodes in the tree is in the range [0, 5000].

  • -104 <= Node.val <= 104

Deep-Dive & Conceptual Insights

Core Insight

Returning -1 from subtrees allows instant failure propagation without computing full tree depths.

Real-World Scenario & Production Applications

Self-balancing AVL/Red-Black tree rebalancing triggers, database index tree verification.

Step-by-Step Execution Trace Table

NodeLeft HeightRight HeightDifferenceStatus
15 (leaf)000Balanced (h=1)
7 (leaf)000Balanced (h=1)
20110Balanced (h=2)
9 (leaf)000Balanced (h=1)
3 (root)121Balanced (h=3)
Trace Inputroot = [3,9,20,null,null,15,7]
Expectedtrue
NodeLeft HeightRight HeightDifferenceStatus
15 (leaf)000Balanced (h=1)
7 (leaf)000Balanced (h=1)
20110Balanced (h=2)
9 (leaf)000Balanced (h=1)
3 (root)121Balanced (h=3)
Code Shape
Archetype Code Shape
Python
1def check_height(node):
2 if not node:
3 return 0
4 left, right = check_height(node.left), check_height(node.right)
5 if left == -1 or right == -1 or abs(left - right) > 1:
6 return -1
7 return max(left, right) + 1
8return check_height(root) != -1

Conceptual Narrative

🧭 Conceptual Foundation & Pattern Intuition

The obvious approach — compute each subtree's height, then separately check balance at each node — re-walks the same subtrees over and over. This trick answers both questions in a single pass by hijacking the return value.

🏗️ The Analogy: A Building Inspector Who Stops at the First Crack

Imagine a building inspector checking a tower floor by floor, from the top down conceptually, but reporting bottom-up. At each floor, they want to report how tall the tower is above this point — but if they ever discover a structural imbalance below, there's no point continuing to measure heights accurately; they just need to report "unsafe" all the way up to whoever's asking, instantly, without finishing the inspection.

🔑 The Key Idea in the Code

-1 is overloaded to mean two different things depending on context: "not yet checked" becomes "structurally broken, stop caring about the real number." Once any subtree reports -1, every ancestor just relays -1 straight up without doing any more work — a free early exit riding on the same recursive call that computes height.

  • Quadratic O(N2)O(N^2)O(N2) top-down traversal: Calling height(node.left) and height(node.right) at each level recomputes subtree depths redundantly. A bottom-up DFS returning -1 on imbalance computes balance in O(N)O(N)O(N) time.

  • Missing sentinel early-exit propagation: When a child subtree returns -1 (unbalanced), the parent must immediately propagate -1 without computing abs(left - right).

  • Treating difference of 1 as unbalanced: The definition of height-balanced requires abs(left - right) <= 1. Failing when difference equals 1 rejects valid balanced trees.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

Tree height-balance condition + require optimal O(N) single-pass without quadratic depth recalculations.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Invariant: check_height returns actual subtree height if balanced, or -1 if any descendant subtree is unbalanced.

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

  • Forgetting to check if left_h == -1 before checking right subtree.

The 60-Second Interview Pitch

Say this out loud before you type a single line

"I use a bottom-up post-order DFS helper check_height. It returns the height if balanced, or -1 as soon as any subtree is unbalanced. When a child returns -1 or abs(L - R) > 1, it immediately propagates -1 upward. Runs in strict O(N) time and O(H) space."

Big-O Invariant Derivation

Complexity & Mathematical Proof

TIME COMPLEXITY

O(N)

Look at the execution steps: Bottom-up DFS returns tree height or -1 if unbalanced. Any unbalanced subtree short-circuits immediately, visiting each node at most once.

SPACE COMPLEXITY

O(H) Auxiliary

Recursion stack depth equals tree height H.

Formal Recurrence Relation

T(N) = ∑_{v} O(1) = O(N)

Derivation Progression

Bottom-Up Height Compute

H(v) = 1 + max(HL, HR)

Computes height from children in a single post-order traversal.

Early Pruning Sentinel

if |HL - HR| > 1: return -1

Propagates failure upward immediately without redundant visits.

Linear Single Pass

O(N) node visits

Eliminates repeated depth calculations.

Variable Definitions

NNN

Total number of nodes in the binary tree

HHH

Tree height (log N in balanced tree, N in skewed tree)

Memory Architecture & Bounds

🟣 Call Stack

O(H) Call stack (log N <= H <= N)

🔵 Auxiliary Heap

O(1) Zero heap memory

🟢 Output Space

O(1) Boolean balance status

Boundary Best / Worst Cases

Best Case

O(1)O(1)O(1) if root is unbalanced, otherwise O(N)O(N)O(N).

Average Case

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

Worst Case

O(N)O(N)O(N) on balanced tree.

Graph & Tree Traversal Frontier

Graph & Tree Traversal Frontier
Synthesizing vector architecture diagram...
Staff+ Engineering Perspective

Senior SWE Deconstruction & Hardware Caveats

ARCHITECTURAL SIGNALS & INTERVIEW TRIGGERS

Triggers: "height-balanced binary tree", "depth of two subtrees of every node never differs by more than one". Naive top-down calculation computes depth(left) and depth(right) at each node, taking O(N2)O(N^2)O(N2) time. A Senior SWE implements a Bottom-Up Check with Sentinel Early Exit (-1): return actual height if balanced, or -1 if unbalanced to immediately short-circuit up the call stack!

CONSTRAINTS & BOUNDS

N≤5000N \le 5000N≤5000. Time budget is strictly O(N)O(N)O(N) linear time.

FAANG PRODUCTION TRAPS & EDGE CASES

O(N2)O(N^2)O(N2) top-down trap: calling maxDepth inside a separate isBalanced recursive helper causes redundant traversal. The combined height/balance check solves the entire problem in a single post-order pass.

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