WorkspacePatterns
THE ART OF RECOGNITION

See the pattern behind the problem.

Learn the signals that turn an unfamiliar question into a familiar approach.

A LITTLE PRACTICE GOES A LONG WAY

Can you spot the right approach?

Short questions. Useful explanations. Sharper intuition.

Start the trainer

Arrays

A sequence gives every value an index. First decide what information a single pass can maintain.

Indexed sequenceContiguous range
Learn the signals

Strings

Treat text as a sequence, but define what counts as a character before choosing indices.

SubstringCharacter frequency
Learn the signals

HashMap

Trade a little memory for fast answers to: have I seen the value I need?

Fast lookupFrequency counting
Learn the signals

HashSet

Remember membership without storing a separate associated value.

Duplicate detectionAlready visited
Learn the signals

Two Pointers

Maintain two positions whose movement preserves a useful relationship: mirrored characters, a compacted prefix, or a sorted pair sum.

Compare opposite endsStable in-place compaction
Learn the signals

Sliding Window

Maintain a contiguous range, reusing information as its boundaries move.

Longest or shortest substringContiguous subarray
Learn the signals

Prefix Sum

Store the sum of each prefix so an inclusive range can be expressed as the difference of two prefixes.

Many range-sum queriesRepeated sums over immutable input
Learn the signals

Sorting

Reorder values by a chosen key so local comparisons reveal global structure, such as neighboring overlapping ranges.

Ordered groupsSweep by start time
Learn the signals

Binary Search

A comparison proves that one half of the remaining candidates cannot contain the answer.

Sorted inputMonotonic predicate
Learn the signals

Linked List

Follow identity-based links between nodes; position is reached by traversal rather than indexing.

Change next pointersReverse or splice nodes
Learn the signals

Stack

The most recent unfinished task must be resolved first.

Nested matchingLast-in-first-out
Learn the signals

Queue

Process items in the order they were discovered. The oldest unfinished item leaves first.

Breadth-first explorationTasks ready to process
Learn the signals

Deque

Remove or add candidates at either end to maintain a useful frontier, such as decreasing values for window maxima.

Sliding-window maximumExpire oldest candidates
Learn the signals

Recursion

Solve a smaller instance and keep unfinished work in a call frame.

Self-similar subproblemsTree traversal
Learn the signals

Backtracking

Explore a decision tree by choosing an option, solving the smaller remaining task, and undoing the choice before trying another option.

Enumerate combinationsGenerate valid strings
Learn the signals

Fast & Slow Pointers

Follow a deterministic sequence at two speeds to detect a cycle without storing every visited state.

Cycle detectionLinked-list loops
Learn the signals

Trees

A node owns smaller subtrees. Many global answers can be assembled from child answers.

Root-to-leaf pathsSubtree summaries
Learn the signals

Binary Search Tree

Ordering applies to whole subtrees: every left descendant is smaller and every right descendant is greater under a strict-key policy.

Ordered tree lookupValidate subtree ordering
Learn the signals

Heap / Priority Queue

Keep the best-priority item at the root while maintaining only parent–child order, rather than sorting every element.

Top k valuesRepeated min/max extraction
Learn the signals

Trie

Share character-by-character paths so every node represents a prefix and can retain information about words with that prefix.

Prefix lookupAutocomplete
Learn the signals

Graphs

Model entities as vertices and relationships as edges, including implicit edges in a grid.

ConnectivityReachability
Learn the signals

DFS

Explore one branch as far as possible before returning to other frontier entries.

Connected componentsFlood fill
Learn the signals

BFS

Explore vertices in increasing number of edges from the start, using a queue to finish one distance layer before the next.

Fewest unweighted movesNearest reachable target
Learn the signals

Topological Sort

Resolve a directed dependency graph by repeatedly removing vertices with no remaining incoming edges.

Prerequisite feasibilityBuild order
Learn the signals

Union Find

Represent disjoint components by rooted parent forests and merge components by linking their roots.

Incremental undirected connectivityCount components
Learn the signals

Dijkstra

Finalize the nearest unfinished vertex, then relax outgoing edges to improve tentative distances to other vertices.

Nonnegative weighted routesMinimum travel time
Learn the signals

Shortest Path

Associate each vertex with the least cost of reaching it under the problem's allowed moves.

Fewest movesMinimum route length
Learn the signals

Dynamic Programming

Define a reusable answer for each state, then compute states from already solved smaller ones.

Overlapping subproblemsOptimal substructure
Learn the signals

Greedy

Keep the strongest reachable state when a local choice can be proven to preserve every future possibility.

Reachable frontierSafe local choice
Learn the signals

Intervals

Represent each range by its endpoints and sort by start so overlapping groups can be processed in one sweep.

Merge overlapsCalendar ranges
Learn the signals

Bit Manipulation

Use bitwise identities to combine integer state. XOR has identity zero and cancels equal pairs.

Paired values with one exceptionBinary flags
Learn the signals