B E YO N D CR ACK I N G T H E CO D I N G I N T E R V I E W ▸ O N L I N E R E S O U R CE S
TRIGGERS
TWO POINTERS
Trigger Keywords
The input consists of one or two arrays/strings/linked lists. We need to use O(1) extra memory or palindrome, reverse, swap,
modify the input in place. The input is sorted. The naive solution is O(n2), and we want to get to merge, partition
O(n).
BINARY SEARCH
Trigger Keywords
The input is a sorted array/string. The brute force involves repeated linear scans. We are given an sorted, threshold, range,
optimization problem that's hard to optimize directly. boundary, find, search,
minimum/maximum, first/
last, smallest/largest
SETS & MAPS
Trigger Keywords
There is some "key-like" concept in the problem. We are doing multiple linear scans in arrays. The frequency, unique,
input and/or output order is irrelevant in our algorithm. Linear-time target complexity. The problem duplicate, grouping, union,
is a sliding window problem. intersection, anagram,
caching
STACKS & QUEUES
Trigger Keywords
Right-to-left combinations/transformations; undo/redo actions; balanced parenthesis. Brackets like nested, bracket, parentheses
[], (), {}, and <>, quotation marks, code comment markers like /* /, and even the double asterisks
(**) used to bold text in Markdown. Next Greatest Element.
RECURSION
Trigger Keywords
The input data is a recursive data structure or has a recursive or "nesting" nature (e.g., a binary tree or nested, quicksort, merge sort
an array where each element can itself be an array). The problem statement includes a self-referential
definition (e.g., Fibonacci). You find yourself wanting to write a number of nested loops that depend
on the input. The problem is related to merge sort or quicksort.
LINKED LISTS
Trigger Keywords
The input is a linked list. We need O(1) access to both the beginning and the end of a data structure
while maintaining insertion order. Data structure design questions.
GRAPHS
Trigger Keywords
The input is an edge list or a grid. The topic is related to connectivity, reachability, or distance. Prob- path, source, destination,
lems involving pairwise relationships between input elements. Geometric problems. goal, steps, travel, maze,
points
HEAPS
Trigger Keywords
The data is dynamic, like in 'data structure design' questions where the answer changes over time; top/bottom, minimum/
top-k type problems; the naive solution uses sorting; the goal is to optimize the extra space. maximum, largest/smallest,
median
B E YO N D CR ACK I N G T H E CO D I N G I N T E R V I E W ▸ O N L I N E R E S O U R CE S
SLIDING WINDOWS
Trigger Keywords
The input type is just an array of numbers or a string, and maybe a number. The lower bound is linear. subarray, substring, length,
contiguous, consecutive,
range, longest, or shortest
BACKTRACKING
Trigger Keywords
Problems with maximum input sizes in the lower 2-digits; enumeration problems or problems with
exponential-sized outputs in general; NP-complete problems, especially optimization ones; games
and puzzles (like N-queens, sudoku, knight’s tour problem); subset-based or permutation-based
problems; problems where you’d think of using DP but there are no overlapping subproblems.
DYNAMIC PROGRAMMING
Trigger Keywords
It’s an optimization or counting problem, and the naive solution is backtracking. You have to make a
sequence of choices. Path-finding problems where you can’t go back.
GREEDY
Trigger Keywords
optimization problems; interval problems; problems where you’d use backtracking but you need
better-than-exponential runtime.
TOPOLOGICAL SORT
Trigger Keywords
The input is a DAG, or at least a directed graph; there is some notion of dependencies or
prerequisites (even if the input is not a graph); the question is about distances or paths; the runtime
upperbound is linear.
PREFIX SUMS
Trigger Keywords
The input consists of an array/strings. We need to use O(1) extra memory or modify the input in prefix, suffix, partition,
place. Problems with multiple subarrays, especially when sliding windows don’t seem to work. The subarray
input is sorted. The naive solution is O(n2), and we want to get to O(n). Problems with ranges or
intervals.