algorythms

Patterns

22 patterns, structured from fundamentals to advanced. Each builds on the last.

#00

Arrays & Hashing

Use hash maps and hash sets to trade space for time. Convert O(n²) lookups into O(n) by storing values you have seen. The foundation of almost every interview.

0/10 solved0%
"Two Sum" style: find pairs/gr…Detect duplicates or count fre…
#01

Sliding Window

Maintain a window over a contiguous subarray or substring, expanding or shrinking it to satisfy a constraint. Avoids recomputing from scratch on every step.

0/7 solved0%
Find max/min/average of contig…Longest/shortest subarray/subs…
#02

Two Pointers

Use two indices that move toward each other or in the same direction to solve problems on sorted arrays or when looking for pairs/triplets that satisfy a condition.

0/8 solved0%
Sorted array with pair/triplet…Remove duplicates in-place
#03

Fast & Slow Pointers

Floyd's cycle detection: one pointer moves twice as fast. They'll meet if there's a cycle, or fast will hit null if there isn't.

0/4 solved0%
Detect cycle in linked list or…Find middle of linked list in …
#04

Merge Intervals

Sort intervals by start time, then greedily merge overlapping ones. The key insight: if sorted, you only ever need to compare with the last merged interval.

0/5 solved0%
Overlapping intervals problemScheduling / meeting rooms
#05

Cyclic Sort

When numbers are in range [1, N], each number belongs at index (number - 1). Swap each number to its correct position in O(n).

0/4 solved0%
Array of N numbers in range [1…Find missing or duplicate numb…
#06

In-place List Reversal

Reverse a linked list or sublist by re-wiring next pointers in-place using prev, current, next variables. No extra space needed.

0/4 solved0%
Reverse entire linked listReverse a sublist between posi…
#07

Tree BFS

Process a tree level by level using a queue. At each level, snapshot the queue size so you know exactly how many nodes belong to that level.

0/5 solved0%
Level-order traversalMinimum depth / shortest path …
#08

Tree DFS

Explore tree paths using recursion (or explicit stack). Three traversal orders: pre-, in-, post-order. Great for path sums and BST validation.

0/11 solved0%
Root-to-leaf path sumsMax/min depth
#09

Two Heaps

Maintain a max-heap for the lower half and a min-heap for the upper half of a stream. The median is always at their tops.

0/3 solved0%
Find median from data streamProblems requiring dynamic "mi…
#10

Subsets / Combinations

Build all subsets by starting with an empty set and for each element, creating new subsets by adding it to every existing subset (BFS-style expansion).

0/5 solved0%
Generate all subsets / power s…Generate all permutations
#11

Modified Binary Search

Classic binary search adapted: search in rotated arrays, answer-space binary search, or find a boundary condition instead of an exact match.

0/9 solved0%
Sorted or rotated sorted array"Find minimum/maximum X such t…
#12

Monotonic Stack

Maintain a stack that is always increasing or decreasing. When you push a new element, pop all elements that violate the order — those are the elements for which the current one is the answer.

0/8 solved0%
Next greater / next smaller el…Stock span / daily temperature…
#13

Backtracking

Explore all possibilities via recursion, but prune branches that cannot lead to valid solutions. Build the solution incrementally and undo choices when they lead to dead ends.

0/6 solved0%
Generate all valid combination…Constraint satisfaction (Sudok…
#14

Trie

A tree where each node represents a character. Enables O(m) prefix searches (m = word length) instead of O(n·m) linear scan through all words.

0/5 solved0%
Autocomplete / prefix searchWord dictionary with wildcard …
#15

Topological Sort

Order nodes in a DAG such that every directed edge goes from earlier to later. Use BFS (Kahn's algorithm) with in-degree tracking or DFS with a finish-time stack.

0/4 solved0%
Task scheduling with prerequis…Course prerequisites / build o…
#16

Graph BFS / DFS

Traverse graphs using BFS (shortest path, level-by-level) or DFS (connected components, path existence). Always track visited nodes to avoid cycles.

0/13 solved0%
Count connected components / i…Shortest path in unweighted gr…
#17

Dynamic Programming

Break a problem into overlapping subproblems. Memoize results (top-down) or fill a table bottom-up. Works when the problem has optimal substructure.

0/24 solved0%
Count ways / find min/max ways…Optimal substructure: solution…
#18

Bitwise XOR

XOR is its own inverse: a ^ a = 0 and a ^ 0 = a. XOR-ing all elements cancels duplicates, leaving only the unique ones.

0/3 solved0%
Find the single number that ap…Find two numbers appearing an …
#19

Heap / Priority Queue

A heap gives you O(log n) insert and O(1) peek at the min or max. Essential for "Top K", streaming medians, scheduling, and merging sorted streams.

0/11 solved0%
"Top K largest/smallest/freque…Repeatedly extract the minimum…
#20

Stack

LIFO (Last In First Out) data structure. Perfect for parsing strings, evaluating expressions, or matching pairs like parentheses.

0/3 solved0%
Matching pairs like nested par…Evaluating postfix/RPN express…
#21

Game Theory & Minimax

Solve two-player zero-sum games where both players play optimally. Generally solved by exploring all future game states using DP or recognizing a mathematical pattern.

0/3 solved0%
Two players taking turns optim…"Predict the winner" or "Can p…