A way to represent a graph where each node stores a list of its neighbors. More space-efficient than a matrix for sparse graphs (most real graphs). The go-to representation for coding interviews.
Example: Node 0 → [1, 2], Node 1 → [0, 3], Node 2 → [0]. That's a graph with 4 nodes and 4 edges.
adjacency-matrixgraphdirected-graph
Try a choice, go deeper, and if it leads to a dead end, UNDO the choice and try the next option. Like solving a maze by walking forward until you hit a wall, then going back to the last fork and trying a different path.
Example: Generate all valid parentheses: add '(' or ')' at each step, backtrack if it becomes invalid.
recursionpruningconstraint-satisfaction The simplest version of a recursive problem that you can answer directly without recursing further. Every recursion MUST have one, or it runs forever. The base case is where the recursion stops and actual answers start flowing back up.
Example: Factorial: base case is factorial(0) = 1. Without it, factorial(5) would call factorial(4) → factorial(3) → ... forever.
The round where the interviewer asks about past work to predict future behavior. 'Tell me about a time you disagreed with a teammate.' 'Tell me about a failure.' Behind every question is a specific signal the company is grading — ownership, leadership, conflict resolution, clarity under pressure. The wrong move is a rehearsed speech. The right move is a specific, first-person story with a clear outcome and honest reflection.
Example: Use the STAR method — Situation, Task, Action, Result — to keep your story under 3 minutes and make the signal obvious. Pick stories from the last 12 months; older ones read as stale.
Breadth-first search: explore all neighbors at the current depth BEFORE moving deeper. Uses a queue. Finds the shortest path in unweighted graphs. Think: ripple expanding outward from a stone dropped in water.
Example: Number of Islands: BFS from each unvisited '1', marking all connected land as visited. Each BFS call = one island.
dfsqueueshortest-pathlevel-order How your algorithm's time or space grows as the input gets bigger. O(n) means it scales linearly — double the input, double the time. O(n²) means it scales quadratically — double the input, quadruple the time. It's about the SHAPE of growth, not the exact number.
Example: Nested loops over the same array: O(n²). Binary search: O(log n). Hash table lookup: O(1).
Cut the search space in half every step. Only works when the input is sorted (or has a monotonic property). The key insight: if the middle element is too big, the answer must be in the left half. Too small? Right half. O(log n).
Example: Search in a sorted array: check middle → go left or right → repeat. 1 billion elements? Only 30 checks.
A group of nodes in a graph where every node can reach every other node through some path. An isolated island in Number of Islands is one connected component. Counting them is one of the most common graph interview questions.
Example: A social network graph: each friend group that has no connections to other groups is a connected component.
Common Table Expression — a named temporary result set defined with WITH that exists only for the duration of one query. Makes complex queries readable by breaking them into named steps. Think of it as a local variable for SQL.
Example: WITH ranked AS (SELECT *, ROW_NUMBER() OVER (...) AS rn FROM orders) SELECT * FROM ranked WHERE rn = 1 — the CTE 'ranked' makes the query easy to read.
Depth-first search: go as deep as possible down one path before backtracking. Uses a stack (or recursion). Good for exhaustive search, cycle detection, and topological sorting. Think: exploring a cave — go until dead end, then back up.
Example: Generating all permutations: DFS explores every possible ordering by choosing one element at a time and backtracking.
A hash map from element to count — the bookkeeping trick behind half of all string/array interview problems. Build it once in O(n), then decrement as you shrink a window or match against a target. When every count hits zero, you've consumed the target.
Example: Valid Anagram (LC 242): a `frequency map` of `s` minus a `frequency map` of `t` should leave every count at zero — any non-zero count means the two strings aren't anagrams.
Always pick the option that looks best RIGHT NOW, without thinking about future consequences. Sometimes this gives the globally optimal answer (coin change with standard denominations). Sometimes it doesn't (and you need DP instead).
Example: Activity selection: always pick the activity that ends earliest. Greedy works here because early endings leave the most room for future activities.
A data structure that maps keys to values in average O(1) lookup, insert, and delete. It's the hidden engine behind half of all interview problems — Two Sum, Valid Anagram, LRU Cache, Group Anagrams, anything that needs 'have I seen this before?' in constant time. Under the hood: a hash function maps keys to array indices; collisions are resolved with chaining or open addressing.
Example: Two Sum: build a hash map of `value -> index` as you scan the array. For each `x`, check if `target - x` is already in the map. O(n) time, O(n) space, one pass.
The rule that every parent node is smaller (min-heap) or larger (max-heap) than its children. This is what makes finding the minimum or maximum O(1) — it's always sitting at the top.
Example: In a min-heap, the root is always the smallest element. Pop it, and the heap fixes itself in O(log n).
priority-queueheapifybinary-heap
Modifying the input directly without allocating extra space proportional to the input size. An in-place sort rearranges the array itself. A NOT-in-place sort creates a new array. Interviewers love this because it tests whether you understand space complexity.
Example: Reversing an array in-place: swap first and last, move inward. O(1) extra space.
A rule that stays true while your code runs. When the rule is true, the loop is safe to keep going. When it breaks, you move something, shrink something, or stop.
Example: Sliding window: the window has at most k distinct characters. If adding a character breaks that rule, move left until the rule is true again.
loop-invariantpreconditionpostcondition
Saving the result of a function call so you don't compute it again. If `fib(5)` already ran, store the answer and return it instantly next time. The core trick behind dynamic programming.
Example: Without memoization, `fib(40)` makes billions of calls. With it, just 40.
A pointer is either an index you move through a list, or a reference to some object or node. In interview talk, it usually means: keep a finger on this position so you can move it later.
Example: Two pointers: `left` starts at index 0 and `right` starts at the end. Move one pointer when the current pair cannot be the answer.
A recurrence is the rule for getting the current answer from smaller answers. Before the formula looks fancy, ask: what tiny result do I already know, and how does it help this one?
Example: Climbing stairs: ways to reach step 5 = ways to reach step 4 + ways to reach step 3.
Joining a table to itself using two different aliases. Used when you need to compare rows within the same table — like finding employees who earn more than their managers, where both are rows in the Employee table.
Example: SELECT e.name FROM Employee e JOIN Employee m ON e.managerId = m.id WHERE e.salary > m.salary — compares each employee row against their manager row in the same table.
inner-joinaliasforeign-key
A fake value, fake node, or guard case you add so the real logic has fewer exceptions. It does not represent real input. It exists to make the loop easier to reason about.
Example: Largest Rectangle in Histogram: append a fake 0-height bar so the stack drains naturally at the end.
A technique where you maintain a 'window' (a subarray or substring) and slide it across the input, expanding or shrinking it as needed. Instead of checking every possible subarray (O(n²)), you check each element at most twice (O(n)).
Example: Longest substring without repeating characters: expand the window right, shrink from the left when you see a duplicate.
How much extra memory your algorithm uses as the input grows. A recursive DFS on a tree uses O(height) stack space. An extra hash set uses O(n) space. Interviewers test this because real systems have memory limits.
Example: In-place sort: O(1) extra space. Merge sort: O(n) extra space for the temporary array.
A query nested inside another query. It runs first, and its result feeds into the outer query. Subqueries can appear in WHERE (filtering), FROM (as a derived table), or SELECT (scalar value). Often replaceable by JOINs or CTEs for clarity.
Example: SELECT * FROM employees WHERE salary > (SELECT AVG(salary) FROM employees) — the inner query computes the average, the outer filters by it.
How many operations your algorithm performs as the input grows. Expressed in Big O notation. The interviewer's favorite follow-up question: 'what's the time complexity?' If you can't answer, you can't pass.
Example: Sorting: O(n log n). Linear scan: O(n). Nested loop: O(n²). Hash lookup: O(1).
Use two indices moving through an array — usually one from each end moving inward, or both starting at the beginning moving at different speeds. Turns O(n²) brute force into O(n) by eliminating impossible pairs early.
Example: Two Sum II (sorted array): left pointer at start, right at end. Sum too big? Move right left. Too small? Move left right.
A function that computes a value across a set of rows related to the current row WITHOUT collapsing them into one. Unlike GROUP BY, window functions keep every row visible. The OVER clause defines the 'window' — which rows to look at and in what order.
Example: RANK() OVER (PARTITION BY department ORDER BY salary DESC) ranks employees within each department without losing individual rows.