Sliding Window
Solve fixed-window problems: maximum sum of k elements, moving averages, and O(n) updates as the window slides.
Learn algorithms for coding interviews and software: sorting, searching, graphs, dynamic programming, greedy methods, and recursion.
Solve fixed-window problems: maximum sum of k elements, moving averages, and O(n) updates as the window slides.
Scan a sorted array or string from both ends at once to find pairs, remove duplicates, or reverse data in O(n).
Cut a sorted range in half on every step to find a value or boundary in O(log n) instead of checking one by one.
Explore as far as possible down one path before backtracking, used to walk trees, graphs, and grids.
Explore level by level from a starting point, the go-to way to find the shortest path in an unweighted graph.
Break a problem into overlapping subproblems and reuse their answers to avoid recomputing the same work.
Try a choice, keep going, and undo it if it fails, used to generate permutations, combinations, and valid layouts.
Make the locally best choice at each step and never look back, useful when local optima add up to a global optimum.
Repeatedly swap neighboring out-of-order elements until the whole list is sorted, simple but slow on large lists.
Split the list in half, sort each half, then merge them back together in order, giving reliable O(n log n) time.
Pick a pivot, move smaller elements left and larger ones right, then repeat on each side to sort in place.
Build the sorted list one element at a time, inserting each new element into its correct position as you go.
Find the shortest path from a starting node to every other node in a graph where edges have non-negative weights.
Find the shortest path from a starting node even when some edges have negative weights, and detect negative cycles.
Order the nodes of a graph so every task comes after everything it depends on, used for scheduling and build order.
Track which nodes belong to the same group and merge groups quickly, used to detect cycles and build networks.
Build the cheapest network connecting all nodes by adding the smallest edges first, skipping any that form a cycle.
Build the cheapest network connecting all nodes by growing a tree one node at a time, always picking the cheapest edge out.
Solve a problem by having a function call itself on a smaller version of the same problem until it hits a base case.
Repeatedly find the smallest remaining element and move it into place, simple to write but slow on large lists.
Build a heap from the list, then repeatedly pull out the largest element to sort in place in O(n log n).
Count how many times each value appears, then rebuild the list in order, sorting in O(n) when values fall in a small range.
Precompute running totals so the sum of any range can be answered instantly instead of adding it up every time.
Track the best running sum ending at each position to find the maximum sum of a contiguous subarray in one pass.
Try a different search term, or browse concepts by category.