Inspect the data structure, compare complexity, and step through synchronized examples.
Use two pointers moving toward each other to find pairs that satisfy a condition in a sorted array.
Maintain a window of elements and slide it to find optimal subarrays.
Efficiently search in sorted data by eliminating half the search space.
Explore graphs and trees level by level. Great for shortest path.
Explore as deep as possible before backtracking.
Break problems into overlapping subproblems and cache results.
Explore all possible solutions by building incrementally and abandoning ("backtracking") when constraints are violated.
LIFO data structure for parentheses, expression evaluation.
Efficiently get min/max elements. Top K problems.
Precompute cumulative sums to answer range queries in O(1).
Fast/slow pointers for cycle detection, reversal, merging.
Make locally optimal choices hoping for global optimum.
Use bitwise XOR, AND, OR for efficient solutions.
Sort intervals and merge overlapping ones. Key for scheduling problems.
Maintain a stack with elements in increasing/decreasing order for next greater/smaller problems.
Use hash maps for O(1) lookup, frequency counting, and grouping.
Advanced graph algorithms including topological sort, shortest paths, and MST.
System design problems like LRU Cache, LFU Cache, and data structure design.
Sorting-based solutions using custom comparators and sorted properties.
Tree-like data structure for efficient prefix-based string operations and autocomplete.
Mathematical operations including modular arithmetic, matrix operations, and computational geometry.
Recursive traversal patterns for binary trees: depth, diameter, ancestors, and validation.
Efficiently track connected components and detect cycles using disjoint sets with path compression and union by rank.
Efficiently answer range queries and updates in O(log n) time using a binary tree structure.
Efficiently search for patterns in strings using KMP, Rabin-Karp, or wildcard matching algorithms.