Interview Problems
DSA Interview Problems
Sorting Algorithms
Pattern-by-pattern interview practice: every problem pairs a short written explanation with a step-by-step visualization, so you can see the idea behind the solution before memorising the code.
Seventeen sorting algorithms on the same shuffled data — watch comparisons, swaps, pivots and heaps rearrange bars step by step.
Big-O: Best O(n log n) comparison sorts; counting/radix/bucket reach O(n + k) on small integer keys.
def longest_consecutive(nums):
uniq = sorted(set(nums))
best, run = 0, 1
for i in range(len(uniq)):
if i and uniq[i] == uniq[i - 1] + 1:
run += 1
best = max(best, run)
else:
run = 1
return max(best, 1 if uniq else 0)Behind the Scenes Execution
Press ▶ Run in the visualizer — the call stack, registers and memory will replay here in sync with the code, line by line.
How to work through these problems
Every entry pairs three things that are usually taught separately: a short written explanation of the idea, the same idea animated on a small fixed input, and a line-by-line trace of what the machine is holding while it runs. Read the explanation first, predict what the first frame will show, then press run and check yourself. The prediction step is what turns watching into practising — if your expected array state and the highlighted cells disagree, the animation has found a gap in your mental model, which is exactly the moment worth slowing down for.
The Behind the Scenes panel is the part most learners skip. It shows the pointers, loop counters, accumulated results and bound variables that the code is actually using, so a pattern stops being a shape to memorise and becomes a small state machine you can reason about. When you can name the invariant — “the window always contains distinct characters”, “the stack is monotonic”, “dp[i] is the best answer for the first i items” — you can reconstruct the solution in an interview instead of recalling it.
How the 20 pattern categories fit together
The categories trace the order in which the techniques build on each other. Two pointers, sliding window and stack problems are array and string reasoning with a single invariant held across a scan. Binary search variants and prefix sums move the work to the preprocessing step. Recursion and backtracking turn the scan into a search tree, divide and conquer and dynamic programming add memoisation to that tree, and greedy problems are the special case where no lookahead is needed. Graphs, trees, heaps, intervals, bit manipulation and number theory then apply those skeletons to a different representation, and the remaining groups — strings, geometry, combinatorics, randomised algorithms and game theory — are the specialised end of the same toolkit.
A suggested study progression
Start with two pointers and sliding window: they are short, visual and cover the largest share of screening questions. Add stacks and binary search next, because both appear inside larger solutions rather than on their own. Move to recursion, then backtracking, and only then to dynamic programming — attempting DP before recursion feels fluent is the most common reason candidates stall. After that, work by weakness rather than by list order: pick one graph problem, one heap problem and one interval problem per session so the structures stay warm. Revisit a solved problem a week later and re-derive the invariant from the animation before reading the code; spaced re-derivation is what makes the pattern available under interview pressure.
Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Keep the momentum going
Step through a related structure, pattern or course — the ideas reinforce each other and stick faster.