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•Graph Algorithms
HardLC 269

Alien Dictionary (LeetCode 269)

Target Frequency:GoogleMetaAmazon

Imagine a freshly invented language built on the same 26 letters we use, except nobody has told you what order those letters actually rank in.

You're handed words, a dictionary-style list of strings from that language, already arranged in the sequence the language's real (but hidden) letter order would produce.

Work out that hidden order: return one string containing every distinct letter that appears across words, arranged from earliest to latest in the language's own ordering. If the list can't have come from any consistent ordering, return "" instead. If more than one ordering fits the evidence, returning any one of them is accepted.

Worked Examples

Example 1
Input:words = ["wrt","wrf","er","ett","rftt"]
Output:"wertf"
Explanation: Comparing neighbouring words: wrt/wrf puts t before f, wrf/er puts w before e, er/ett puts r before t, and ett/rftt puts e before r. Together: w, e, r, t, f.
Example 2
Input:words = ["z","x"]
Output:"zx"
Explanation: z comes before x in the list, so z ranks first.
Example 3
Input:words = ["z","x","z"]
Output:""
Explanation: The order is invalid, so return "".

⚖️Formal Constraints & Bounds

  • 1 <= words.length <= 100

  • 1 <= words[i].length <= 100

  • words[i] consists of only lowercase English letters.

Deep-Dive & Conceptual Insights

Core Insight

First differing character between adjacent sorted words uniquely defines order constraints.

Real-World Scenario & Production Applications

Deciphering unknown sequential ordering from comparative data, sorting key inference.

Step-by-Step Execution Trace Table

Word PairDiffering CharsExtracted Directed Edge
'wrt' vs 'wrf''t' != 'f't -> f
'wrf' vs 'er''w' != 'e'w -> e
'er' vs 'ett''r' != 't'r -> t
'ett' vs 'rftt''e' != 'r'e -> r
Topological Order'w' -> 'e' -> 'r' -> 't' -> 'f''wertf'
Trace Inputwords = ["wrt","wrf","er","ett","rftt"]
Expected"wertf"
Word PairDiffering CharsExtracted Directed Edge
'wrt' vs 'wrf''t' != 'f't -> f
'wrf' vs 'er''w' != 'e'w -> e
'er' vs 'ett''r' != 't'r -> t
'ett' vs 'rftt''e' != 'r'e -> r
Topological Order'w' -> 'e' -> 'r' -> 't' -> 'f''wertf'
Code Shape
Archetype Code Shape
Python
1adj = {c: set() for c in all_chars}
2in_degree = {c: 0 for c in all_chars}
3compare adjacent words to find first differing char edge w1[j] -> w2[j]
4queue = deque(chars with in_degree 0)
5order = []
6while queue:
7 c = queue.popleft()
8 order.append(c)
9 for nxt in adj[c]:
10 in_degree[nxt] -= 1
11 if in_degree[nxt] == 0:
12 queue.append(nxt)
13return ''.join(order) if len(order) == len(in_degree) else ''

Conceptual Narrative

Alien Dictionary reconstructs an unknown alphabet's lexicographical order by extracting pairwise character precedence constraints from a sorted word list.

🧭 Conceptual Foundation & Pattern Intuition

Given lexicographically sorted words in an alien language, deduce the alphabetical order. Comparing adjacent words w1 and w2 identifies the first mismatching character w1[k] != w2[k], proving w1[k] precedes w2[k] (w1[k]→w2[k]w_1[k] \to w_2[k]w1​[k]→w2​[k]). Topological sorting on the resulting character DAG(Directed Acyclic Graph) yields the alphabet.

🏟️ The Analogy: Stone Tablet Inscriptions

Archaeologists find a stone ledger of sorted words. Comparing 'apple' and 'apply' proves 'e' precedes 'y'. Comparing 'zebra' and 'zoo' proves 'e' precedes 'o'. Stitching these pairwise clues together reconstructs the complete alphabet.

🔑 Why It Works

Prefix Invalidity Trap: If word 2 is a strict prefix of word 1 (e.g. ['abc', 'ab']), the dictionary is fundamentally invalid (like 'apple' appearing before 'app' in English). Return '' immediately.

  • Prefix truncation invalidity: Failing to detect ['abc', 'ab'] where a longer word precedes its own prefix; this is an invalid lexicographical order and must return ''.

  • Comparing non-adjacent word pairs: Comparing all O(N2)O(N^2)O(N2) word pairs generates redundant edges and false transitive cycles; comparing adjacent words O(N)O(N)O(N) is necessary and sufficient.

  • Missing isolated characters: Dropping characters that appear in words but have zero incoming or outgoing edges from the final result string.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

Inferring total ordering from lexicographically sorted sequences.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Invariant: character adjacency graph is a DAG(Directed Acyclic Graph) if and only if alphabet order is valid.

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

  • Cycles in character ordering: e.g. ['z', 'x', 'z'] creates z -> x and x -> z cycle.

The 60-Second Interview Pitch

Say this out loud before you type a single line

"I create adjacency and in-degree maps for all unique characters. I compare adjacent words to find the first differing character, creating a directed edge w1[j] -> w2[j]. If word 1 has word 2 as prefix, I return ''. I run Kahn's algorithm to produce the order string. Runs in O(C) total characters time and O(U) unique characters space."

Big-O Invariant Derivation

Complexity & Mathematical Proof

TIME COMPLEXITY

O(C)

Look at the execution steps: Let C be total length of all words in word list, V be number of unique characters (<= 26), and E be derived precedence edges. Deriving edges takes O(C); Kahn's topological sort takes O(V + E). Total O(C).

SPACE COMPLEXITY

O(V + E) Auxiliary

Look at memory allocations: Call stack uses O(1) Iterative. Adjacency list and in-degree map for at most 26 lowercase English letters, taking O(1) bounded auxiliary space (or O(V + E)).

Formal Recurrence Relation

T(C) = O(C) + O(V + E) = O(C)

Derivation Progression

Adjacent Word Precedence Extraction

for (w1, w2) in pairs: find first differing char

Extracts directed dependency u -> v in O(C) total string comparisons.

Invalid Prefix Pruning

if w1 starts with w2 and |w1| > |w2|: return ""

Catches prefix violations in O(min(|w1|, |w2|)).

Topological Alphabet Linearization

O(V + E) ≤ O(26 + 262) = O(1)

Kahn's BFS emits unique alien character order.

Variable Definitions

CCC

Total combined character length across all dictionary words

VVV

Number of unique alien alphabet letters (at most 26)

EEE

Derived character precedence ordering edges (at most 26^2)

Memory Architecture & Bounds

🟣 Call Stack

O(1) Iterative

🔵 Auxiliary Heap

O(1) Graph bounded by 26 lowercase English letters

🟢 Output Space

O(V) Character order string (<= 26 chars)

Boundary Best / Worst Cases

Best Case

O(C)O(C)O(C)

Average Case

O(C)O(C)O(C)

Worst Case

O(C)O(C)O(C)

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: "alien language sorted lexicographically", "reconstruct alphabet order". Order reconstruction from adjacent sorted pairs: for words w1w_1w1​ and w2w_2w2​, the first differing character w1[k]eqw_1[k] eq w1​[k]eqw_{2}[k][k][k] establishes a directed edge $$w_{1}[k]→[k] → [k]→w_{2}[k][k][k]. A Senior SWE constructs the letter DAG(Directed Acyclic Graph) and runs Kahn's Algorithm.

CONSTRAINTS & BOUNDS

Words ≤100\le 100≤100, length ≤100\le 100≤100. Alphabet size Σ≤26\Sigma \le 26Σ≤26. Time budget O(C)O(C)O(C) where CCC is total characters across all words.

FAANG PRODUCTION TRAPS & EDGE CASES

Prefix Invalidation Trap: If w1w_1w1​ starts with w2w_2w2​ but len(w1)>len(w2)len(w_1) > len(w_2)len(w1​)>len(w2​) (e.g. "apple" before "app"), the dictionary is invalid: return "" immediately!

Theory Context•Graph Algorithms
HardLC 269

Alien Dictionary (LeetCode 269)

Target Frequency:GoogleMetaAmazon

Imagine a freshly invented language built on the same 26 letters we use, except nobody has told you what order those letters actually rank in.

You're handed words, a dictionary-style list of strings from that language, already arranged in the sequence the language's real (but hidden) letter order would produce.

Work out that hidden order: return one string containing every distinct letter that appears across words, arranged from earliest to latest in the language's own ordering. If the list can't have come from any consistent ordering, return "" instead. If more than one ordering fits the evidence, returning any one of them is accepted.

Worked Examples

Example 1
Input:words = ["wrt","wrf","er","ett","rftt"]
Output:"wertf"
Explanation: Comparing neighbouring words: wrt/wrf puts t before f, wrf/er puts w before e, er/ett puts r before t, and ett/rftt puts e before r. Together: w, e, r, t, f.
Example 2
Input:words = ["z","x"]
Output:"zx"
Explanation: z comes before x in the list, so z ranks first.
Example 3
Input:words = ["z","x","z"]
Output:""
Explanation: The order is invalid, so return "".

⚖️Formal Constraints & Bounds

  • 1 <= words.length <= 100

  • 1 <= words[i].length <= 100

  • words[i] consists of only lowercase English letters.

Deep-Dive & Conceptual Insights

Core Insight

First differing character between adjacent sorted words uniquely defines order constraints.

Real-World Scenario & Production Applications

Deciphering unknown sequential ordering from comparative data, sorting key inference.

Step-by-Step Execution Trace Table

Word PairDiffering CharsExtracted Directed Edge
'wrt' vs 'wrf''t' != 'f't -> f
'wrf' vs 'er''w' != 'e'w -> e
'er' vs 'ett''r' != 't'r -> t
'ett' vs 'rftt''e' != 'r'e -> r
Topological Order'w' -> 'e' -> 'r' -> 't' -> 'f''wertf'
Trace Inputwords = ["wrt","wrf","er","ett","rftt"]
Expected"wertf"
Word PairDiffering CharsExtracted Directed Edge
'wrt' vs 'wrf''t' != 'f't -> f
'wrf' vs 'er''w' != 'e'w -> e
'er' vs 'ett''r' != 't'r -> t
'ett' vs 'rftt''e' != 'r'e -> r
Topological Order'w' -> 'e' -> 'r' -> 't' -> 'f''wertf'
Code Shape
Archetype Code Shape
Python
1adj = {c: set() for c in all_chars}
2in_degree = {c: 0 for c in all_chars}
3compare adjacent words to find first differing char edge w1[j] -> w2[j]
4queue = deque(chars with in_degree 0)
5order = []
6while queue:
7 c = queue.popleft()
8 order.append(c)
9 for nxt in adj[c]:
10 in_degree[nxt] -= 1
11 if in_degree[nxt] == 0:
12 queue.append(nxt)
13return ''.join(order) if len(order) == len(in_degree) else ''

Conceptual Narrative

Alien Dictionary reconstructs an unknown alphabet's lexicographical order by extracting pairwise character precedence constraints from a sorted word list.

🧭 Conceptual Foundation & Pattern Intuition

Given lexicographically sorted words in an alien language, deduce the alphabetical order. Comparing adjacent words w1 and w2 identifies the first mismatching character w1[k] != w2[k], proving w1[k] precedes w2[k] (w1[k]→w2[k]w_1[k] \to w_2[k]w1​[k]→w2​[k]). Topological sorting on the resulting character DAG(Directed Acyclic Graph) yields the alphabet.

🏟️ The Analogy: Stone Tablet Inscriptions

Archaeologists find a stone ledger of sorted words. Comparing 'apple' and 'apply' proves 'e' precedes 'y'. Comparing 'zebra' and 'zoo' proves 'e' precedes 'o'. Stitching these pairwise clues together reconstructs the complete alphabet.

🔑 Why It Works

Prefix Invalidity Trap: If word 2 is a strict prefix of word 1 (e.g. ['abc', 'ab']), the dictionary is fundamentally invalid (like 'apple' appearing before 'app' in English). Return '' immediately.

  • Prefix truncation invalidity: Failing to detect ['abc', 'ab'] where a longer word precedes its own prefix; this is an invalid lexicographical order and must return ''.

  • Comparing non-adjacent word pairs: Comparing all O(N2)O(N^2)O(N2) word pairs generates redundant edges and false transitive cycles; comparing adjacent words O(N)O(N)O(N) is necessary and sufficient.

  • Missing isolated characters: Dropping characters that appear in words but have zero incoming or outgoing edges from the final result string.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

Inferring total ordering from lexicographically sorted sequences.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Invariant: character adjacency graph is a DAG(Directed Acyclic Graph) if and only if alphabet order is valid.

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

  • Cycles in character ordering: e.g. ['z', 'x', 'z'] creates z -> x and x -> z cycle.

The 60-Second Interview Pitch

Say this out loud before you type a single line

"I create adjacency and in-degree maps for all unique characters. I compare adjacent words to find the first differing character, creating a directed edge w1[j] -> w2[j]. If word 1 has word 2 as prefix, I return ''. I run Kahn's algorithm to produce the order string. Runs in O(C) total characters time and O(U) unique characters space."

Big-O Invariant Derivation

Complexity & Mathematical Proof

TIME COMPLEXITY

O(C)

Look at the execution steps: Let C be total length of all words in word list, V be number of unique characters (<= 26), and E be derived precedence edges. Deriving edges takes O(C); Kahn's topological sort takes O(V + E). Total O(C).

SPACE COMPLEXITY

O(V + E) Auxiliary

Look at memory allocations: Call stack uses O(1) Iterative. Adjacency list and in-degree map for at most 26 lowercase English letters, taking O(1) bounded auxiliary space (or O(V + E)).

Formal Recurrence Relation

T(C) = O(C) + O(V + E) = O(C)

Derivation Progression

Adjacent Word Precedence Extraction

for (w1, w2) in pairs: find first differing char

Extracts directed dependency u -> v in O(C) total string comparisons.

Invalid Prefix Pruning

if w1 starts with w2 and |w1| > |w2|: return ""

Catches prefix violations in O(min(|w1|, |w2|)).

Topological Alphabet Linearization

O(V + E) ≤ O(26 + 262) = O(1)

Kahn's BFS emits unique alien character order.

Variable Definitions

CCC

Total combined character length across all dictionary words

VVV

Number of unique alien alphabet letters (at most 26)

EEE

Derived character precedence ordering edges (at most 26^2)

Memory Architecture & Bounds

🟣 Call Stack

O(1) Iterative

🔵 Auxiliary Heap

O(1) Graph bounded by 26 lowercase English letters

🟢 Output Space

O(V) Character order string (<= 26 chars)

Boundary Best / Worst Cases

Best Case

O(C)O(C)O(C)

Average Case

O(C)O(C)O(C)

Worst Case

O(C)O(C)O(C)

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: "alien language sorted lexicographically", "reconstruct alphabet order". Order reconstruction from adjacent sorted pairs: for words w1w_1w1​ and w2w_2w2​, the first differing character w1[k]eqw_1[k] eq w1​[k]eqw_{2}[k][k][k] establishes a directed edge $$w_{1}[k]→[k] → [k]→w_{2}[k][k][k]. A Senior SWE constructs the letter DAG(Directed Acyclic Graph) and runs Kahn's Algorithm.

CONSTRAINTS & BOUNDS

Words ≤100\le 100≤100, length ≤100\le 100≤100. Alphabet size Σ≤26\Sigma \le 26Σ≤26. Time budget O(C)O(C)O(C) where CCC is total characters across all words.

FAANG PRODUCTION TRAPS & EDGE CASES

Prefix Invalidation Trap: If w1w_1w1​ starts with w2w_2w2​ but len(w1)>len(w2)len(w_1) > len(w_2)len(w1​)>len(w2​) (e.g. "apple" before "app"), the dictionary is invalid: return "" immediately!

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