① Understand
Restate the input/output. Ask about constraints, duplicates, empty input, ordering, and whether mutation is allowed.
Learn patterns, then solve problems
Read the problem. Write your code. Run a test. Compare the solution when you are ready.
Restate the input/output. Ask about constraints, duplicates, empty input, ordering, and whether mutation is allowed.
Trace one normal case, one boundary case, and one case that could break a naive approach.
Look for a pair, a range, nested structure, repeated subproblem, graph reachability, or a top-K requirement.
Explain what remains true as pointers, window bounds, visited sets, or DP states change.
Explain why the algorithm cannot miss a valid answer; state time and extra space honestly.
Check empty, singleton, duplicates, all-equal, boundaries, overflow, cycles, and repeated calls.
These visual sketches are mental models. Open a problem below to see its own example trace and implementations.
Remember what has appeared so far.
Store value → index; look up the complement.
Use order or a partition to eliminate candidates.
Change one pointer based on the current sum/comparison.
Maintain a valid contiguous range.
Expand right; shrink left when the invariant breaks.
Keep unresolved items until a match arrives.
Pop smaller unresolved values when a warmer day appears.
Discard half of a monotonic search space each step.
Maintain a precise inclusive or half-open interval.
Visit nodes while tracking what is discovered.
DFS for depth/path reasoning; BFS for layers/shortest unweighted paths.
Reuse answers to smaller subproblems.
Define state, recurrence, base case, and evaluation order.
Explore choices and undo them when returning.
Choose → recurse → un-choose; prune impossible branches.
Keep only the best K candidates as data streams in.
A bounded min-heap keeps the K largest values.
Sort by a boundary, then combine compatible ranges.
Sort once; make a locally safe choice with a clear invariant.
First 10 DSA problems are free. Pro unlocks the complete set and remote code execution. Your drafts stay in this tab.
Select a problem to start practicing.