Skip to content
UPEEC

Problem-Solving Patterns

Recurring techniques that crack interview and competitive-programming problems.

Intermediate
Comments 0

This is an overview — pick a sub-topic below.

Sub-topics (18)

Hashing Patterns

Use hash maps for counting, complement lookups and grouping.

Easy♥ 0🔖 0💬 0

Monotonic Stack

A stack kept in increasing or decreasing order to find next greater/smaller elements in $O(n)$.

Intermediate♥ 0🔖 0💬 0

Monotonic Queue

A deque kept in order to report a sliding-window maximum/minimum in $O(n)$ total.

Advanced♥ 0🔖 0💬 0

Interval Problems

Merge, insert or schedule intervals — usually after sorting by start or end.

Intermediate♥ 0🔖 0💬 0

Meet in the Middle

Split a search into two halves of size $n/2$, enumerate each, then combine — $O(2^{n/2})$ instead of $O(2^n)$.

Advanced♥ 0🔖 0💬 0

Coordinate Compression

Map large or sparse values to ranks $0..k-1$ so arrays and Fenwick trees can index them.

Intermediate♥ 0🔖 0💬 0

Top-K Problems

Find the $k$ largest/most frequent items with a size-$k$ heap in $O(n\log k)$, or quickselect in $O(n)$ average.

Easy♥ 0🔖 0💬 0

Reservoir Sampling

Pick $k$ random items uniformly from a stream of unknown length using $O(k)$ memory.

Intermediate♥ 0🔖 0💬 0

Randomized Algorithms

Use randomness for simplicity or expected speed: randomized quicksort, hashing, Monte Carlo methods.

Advanced♥ 0🔖 0💬 0

Offline Queries

Read all queries first, reorder them (e.g. Mo's algorithm, sorting by endpoint), then answer.

Advanced♥ 0🔖 0💬 0

Sweep Line Pattern

Convert intervals into start/end events, sort them, and sweep while tracking counts.

Advanced♥ 0🔖 0💬 0

Game Theory

Determine winners of two-player games with optimal play.

Advanced♥ 0🔖 0💬 0

Bitmask DP

DP over subsets encoded as bits — $O(2^n \cdot n)$ states.

Advanced♥ 0🔖 0💬 0

Tree DP

DP computed bottom-up over a tree (children before parents).

Advanced♥ 0🔖 0💬 0

Digit DP

Count numbers up to $N$ with digit properties by processing digits left to right with a "tight" flag.

Expert♥ 0🔖 0💬 0

Shortest Path Patterns

Choose the right algorithm for the graph: BFS (unweighted), 0-1 BFS (weights 0/1), Dijkstra (non-negative), Bellman-Ford (negative), Floyd-Warshall (all pairs), DAG DP.

Intermediate♥ 0🔖 0💬 0

Competitive Programming

Solve algorithmic problems fast and correctly under time limits.

Intermediate♥ 0🔖 0💬 0

Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.

Discussion (0)

Sign in or join free to ask questions and discuss this topic.