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•Two Pointers & Sliding Window
EasyLC 141

Linked List Cycle (LeetCode 141)

Target Frequency:AmazonMicrosoftApple

You're given head, the first node of a linked list. Figure out whether the list loops back on itself anywhere — that is, whether repeatedly following next pointers can revisit a node you've already seen.

(Internally the test harness marks such a loop with an index pos pointing at the node the tail wraps back to — or -1 if there's no loop — but your function never receives pos directly.)

Return true if a cycle exists, false otherwise.

Worked Examples

Example 1
Input:head = [3,2,0,-4], pos = 1
Output:true
Cyclic Linked List TopologyCycle at Node[1]
Floyd Cycle Detection
Access Road (L):1 node
Cycle Loop (C):3 nodes
Loop Entry:Node[1] (val: 2)
Collision / Meeting Point Detected!
3[0] head🐢 slow🐇 fast2[1] 0[2] -4[3] tailnext = Node[1]
Fast / Slow Pointer Invariant

Slow advances 1 step (slow = slow.next) while Fast advances 2 steps (fast = fast.next.next). The distance between them decreases by 1 on every cycle iteration.

Cycle Origin Recovery ($L = kC - M$)

Upon collision inside the loop, moving one pointer back to the list head and advancing both at 1 step guarantees they will collide at the exact cycle entrance node.

320-4
Explanation: The list's tail (-4) loops back to the node at index 1 (value 2), so a cycle exists.
Example 2
Input:head = [1,2], pos = 0
Output:true
12
Explanation: The list's tail (2) loops back to the node at index 0 (value 1), so a cycle exists.
Example 3
Input:head = [1], pos = -1
Output:false
1
Explanation: pos = -1 means the tail points to nothing, so the list has no cycle.

⚖️Formal Constraints & Bounds

  • The number of the nodes in the list is in the range [0, 104].

  • -105 <= Node.val <= 105

  • pos is -1 or a valid index in the linked-list.

Deep-Dive & Conceptual Insights

Core Insight

Inside a cycle of length C, the relative gap between fast (2 hops) and slow (1 hop) decreases by exactly 1 each turn, guaranteeing collision in at most C steps.

Real-World Scenario & Production Applications

Memory leak detection in reference-counted pointer graphs and cyclic deadlock detection in distributed transaction coordinators.

Step-by-Step Execution Trace Table

Tick / IterationSlow Pointer (slow.val)Fast Pointer (fast.val)Fast Traversal StepCondition Check (slow == fast)
InitNode(3) [index 0]Node(3) [index 0]Pointers initialized at headLoop begins: slow != fast check after move
1Node(2) [index 1]Node(0) [index 2]slow advances 1; fast advances 2 (3 -> 2 -> 0)Node(2) != Node(0) →\to→ Continue
2Node(0) [index 2]Node(2) [index 1]slow advances 1; fast wraps cycle (0 -> -4 -> 2)Node(0) != Node(2) →\to→ Continue
3Node(-4) [index 3]Node(-4) [index 3]slow advances 1; fast advances 2 (2 -> 0 -> -4)Node(-4) == Node(-4) →\to→ Cycle Detected (True)
Code Shape
Archetype Code Shape
Python
1slow, fast = head, head
2while fast and fast.next:
3 slow = slow.next
4 fast = fast.next.next
5 if slow == fast:
6 return True
7return False

Conceptual Narrative

🧭 Conceptual Foundation & Pattern Intuition

Two runners on the same looping track, moving at different speeds, will always eventually meet — that guarantee is the entire algorithm.

🏟️ The Analogy: Two Runners on a Circular Track

Picture two runners on a circular track: a jogger and a sprinter moving exactly twice as fast. If the track were a straight, endless road, the sprinter would just pull ahead forever and the two would never meet again. But on a loop, the sprinter eventually laps the jogger from behind — and "getting lapped" is really just "the gap between them, which shrinks by one step every round, eventually hits zero." If there's no loop at all — just a straight dead-end road — the sprinter simply runs off the end, and no meeting ever happens.

🔑 The Key Idea in the Code

Because fast closes the gap to slow by exactly one node every single step once both are inside a cycle, the collision isn't a matter of luck — it's mathematically guaranteed to happen within one full lap of the cycle.

  • Dereferencing null on fast.next: Always guard while fast and fast.next: before advancing fast = fast.next.next. Checking only while fast: crashes on even-length lists.

  • Comparing node values instead of node identities: In cyclic lists, two distinct nodes may have identical .val. You must compare node references (slow is fast), not values (slow.val == fast.val).

  • Starting both pointers at head with while slow != fast: If both start at head, the while condition while slow != fast terminates before taking a single step. Advance pointers once or initialize fast = head.next.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

Linked list or functional sequence + cycle detection + O(1) space constraint.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Invariant: within a cycle of length C, fast gains 1 step per iteration on slow, guaranteeing collision within C steps.

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 initialize slow = head and fast = head. In a loop, slow moves 1 step and fast moves 2 steps. If fast or fast.next is null, no cycle exists. If slow == fast, a cycle is detected. Runs in O(N) time with O(1) auxiliary space."

Big-O Invariant Derivation

Complexity & Mathematical Proof

TIME COMPLEXITY

O(N)

Look at the execution steps: Slow moves 1 step, fast moves 2 steps. If cycle of length K exists, distance between fast and slow decreases by 1 each step, meeting in at most N iterations.

SPACE COMPLEXITY

O(1) Auxiliary

Look at memory allocations: Call stack uses O(1) Iterative. Only stores two pointer references in O(1) auxiliary space.

Formal Recurrence Relation

T(N) ≤ N + K = O(N)

Derivation Progression

Distance Contraction

Distance closes by 1 step each loop

In each step, fast gains 1 node on slow within a cycle of length K.

Meeting Step Bound

≤ K ≤ N steps to meet

Pointers must intersect within K cycles after slow enters the loop.

Linear Bound

O(N) total node hops

Terminates in O(N) operations whether cycle exists or not.

Variable Definitions

NNN

Total number of nodes in the linked list

CCC

Length of cycle (if cycle exists)

Memory Architecture & Bounds

🟣 Call Stack

O(1) Iterative

🔵 Auxiliary Heap

O(1) Two node pointers

🟢 Output Space

O(1) Boolean return

Boundary Best / Worst Cases

Best Case

O(1)O(1)O(1) if no cycle on small list.

Average Case

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

Worst Case

O(N)O(N)O(N) if cycle is at end.

Pointer Invariant Transition Progression

Pointer Invariant Transition Progression
Synthesizing vector architecture diagram...
Staff+ Engineering Perspective

Senior SWE Deconstruction & Hardware Caveats

ARCHITECTURAL SIGNALS & INTERVIEW TRIGGERS

Triggers: "determine if linked list has a cycle", "can you solve it using O(1) memory?". Floyd's Cycle Finding Algorithm (Tortoise and Hare).

CONSTRAINTS & BOUNDS

Number of nodes 0≤N≤1040 \le N \le 10^40≤N≤104. Requires strictly O(N)O(N)O(N) time and O(1)O(1)O(1) auxiliary memory.

FAANG PRODUCTION TRAPS & EDGE CASES

Null checks: must check while fast and fast.next to avoid dereferencing fast.next.next on acyclic lists. Empty list or single node without cycle returns False safely.

Theory Context•Two Pointers & Sliding Window
EasyLC 141

Linked List Cycle (LeetCode 141)

Target Frequency:AmazonMicrosoftApple

You're given head, the first node of a linked list. Figure out whether the list loops back on itself anywhere — that is, whether repeatedly following next pointers can revisit a node you've already seen.

(Internally the test harness marks such a loop with an index pos pointing at the node the tail wraps back to — or -1 if there's no loop — but your function never receives pos directly.)

Return true if a cycle exists, false otherwise.

Worked Examples

Example 1
Input:head = [3,2,0,-4], pos = 1
Output:true
Cyclic Linked List TopologyCycle at Node[1]
Floyd Cycle Detection
Access Road (L):1 node
Cycle Loop (C):3 nodes
Loop Entry:Node[1] (val: 2)
Collision / Meeting Point Detected!
3[0] head🐢 slow🐇 fast2[1] 0[2] -4[3] tailnext = Node[1]
Fast / Slow Pointer Invariant

Slow advances 1 step (slow = slow.next) while Fast advances 2 steps (fast = fast.next.next). The distance between them decreases by 1 on every cycle iteration.

Cycle Origin Recovery ($L = kC - M$)

Upon collision inside the loop, moving one pointer back to the list head and advancing both at 1 step guarantees they will collide at the exact cycle entrance node.

320-4
Explanation: The list's tail (-4) loops back to the node at index 1 (value 2), so a cycle exists.
Example 2
Input:head = [1,2], pos = 0
Output:true
12
Explanation: The list's tail (2) loops back to the node at index 0 (value 1), so a cycle exists.
Example 3
Input:head = [1], pos = -1
Output:false
1
Explanation: pos = -1 means the tail points to nothing, so the list has no cycle.

⚖️Formal Constraints & Bounds

  • The number of the nodes in the list is in the range [0, 104].

  • -105 <= Node.val <= 105

  • pos is -1 or a valid index in the linked-list.

Deep-Dive & Conceptual Insights

Core Insight

Inside a cycle of length C, the relative gap between fast (2 hops) and slow (1 hop) decreases by exactly 1 each turn, guaranteeing collision in at most C steps.

Real-World Scenario & Production Applications

Memory leak detection in reference-counted pointer graphs and cyclic deadlock detection in distributed transaction coordinators.

Step-by-Step Execution Trace Table

Tick / IterationSlow Pointer (slow.val)Fast Pointer (fast.val)Fast Traversal StepCondition Check (slow == fast)
InitNode(3) [index 0]Node(3) [index 0]Pointers initialized at headLoop begins: slow != fast check after move
1Node(2) [index 1]Node(0) [index 2]slow advances 1; fast advances 2 (3 -> 2 -> 0)Node(2) != Node(0) →\to→ Continue
2Node(0) [index 2]Node(2) [index 1]slow advances 1; fast wraps cycle (0 -> -4 -> 2)Node(0) != Node(2) →\to→ Continue
3Node(-4) [index 3]Node(-4) [index 3]slow advances 1; fast advances 2 (2 -> 0 -> -4)Node(-4) == Node(-4) →\to→ Cycle Detected (True)
Code Shape
Archetype Code Shape
Python
1slow, fast = head, head
2while fast and fast.next:
3 slow = slow.next
4 fast = fast.next.next
5 if slow == fast:
6 return True
7return False

Conceptual Narrative

🧭 Conceptual Foundation & Pattern Intuition

Two runners on the same looping track, moving at different speeds, will always eventually meet — that guarantee is the entire algorithm.

🏟️ The Analogy: Two Runners on a Circular Track

Picture two runners on a circular track: a jogger and a sprinter moving exactly twice as fast. If the track were a straight, endless road, the sprinter would just pull ahead forever and the two would never meet again. But on a loop, the sprinter eventually laps the jogger from behind — and "getting lapped" is really just "the gap between them, which shrinks by one step every round, eventually hits zero." If there's no loop at all — just a straight dead-end road — the sprinter simply runs off the end, and no meeting ever happens.

🔑 The Key Idea in the Code

Because fast closes the gap to slow by exactly one node every single step once both are inside a cycle, the collision isn't a matter of luck — it's mathematically guaranteed to happen within one full lap of the cycle.

  • Dereferencing null on fast.next: Always guard while fast and fast.next: before advancing fast = fast.next.next. Checking only while fast: crashes on even-length lists.

  • Comparing node values instead of node identities: In cyclic lists, two distinct nodes may have identical .val. You must compare node references (slow is fast), not values (slow.val == fast.val).

  • Starting both pointers at head with while slow != fast: If both start at head, the while condition while slow != fast terminates before taking a single step. Advance pointers once or initialize fast = head.next.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

Linked list or functional sequence + cycle detection + O(1) space constraint.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Invariant: within a cycle of length C, fast gains 1 step per iteration on slow, guaranteeing collision within C steps.

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 initialize slow = head and fast = head. In a loop, slow moves 1 step and fast moves 2 steps. If fast or fast.next is null, no cycle exists. If slow == fast, a cycle is detected. Runs in O(N) time with O(1) auxiliary space."

Big-O Invariant Derivation

Complexity & Mathematical Proof

TIME COMPLEXITY

O(N)

Look at the execution steps: Slow moves 1 step, fast moves 2 steps. If cycle of length K exists, distance between fast and slow decreases by 1 each step, meeting in at most N iterations.

SPACE COMPLEXITY

O(1) Auxiliary

Look at memory allocations: Call stack uses O(1) Iterative. Only stores two pointer references in O(1) auxiliary space.

Formal Recurrence Relation

T(N) ≤ N + K = O(N)

Derivation Progression

Distance Contraction

Distance closes by 1 step each loop

In each step, fast gains 1 node on slow within a cycle of length K.

Meeting Step Bound

≤ K ≤ N steps to meet

Pointers must intersect within K cycles after slow enters the loop.

Linear Bound

O(N) total node hops

Terminates in O(N) operations whether cycle exists or not.

Variable Definitions

NNN

Total number of nodes in the linked list

CCC

Length of cycle (if cycle exists)

Memory Architecture & Bounds

🟣 Call Stack

O(1) Iterative

🔵 Auxiliary Heap

O(1) Two node pointers

🟢 Output Space

O(1) Boolean return

Boundary Best / Worst Cases

Best Case

O(1)O(1)O(1) if no cycle on small list.

Average Case

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

Worst Case

O(N)O(N)O(N) if cycle is at end.

Pointer Invariant Transition Progression

Pointer Invariant Transition Progression
Synthesizing vector architecture diagram...
Staff+ Engineering Perspective

Senior SWE Deconstruction & Hardware Caveats

ARCHITECTURAL SIGNALS & INTERVIEW TRIGGERS

Triggers: "determine if linked list has a cycle", "can you solve it using O(1) memory?". Floyd's Cycle Finding Algorithm (Tortoise and Hare).

CONSTRAINTS & BOUNDS

Number of nodes 0≤N≤1040 \le N \le 10^40≤N≤104. Requires strictly O(N)O(N)O(N) time and O(1)O(1)O(1) auxiliary memory.

FAANG PRODUCTION TRAPS & EDGE CASES

Null checks: must check while fast and fast.next to avoid dereferencing fast.next.next on acyclic lists. Empty list or single node without cycle returns False safely.

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