Knowing data structures and algorithms is necessary for a coding interview, but it isn't sufficient — plenty of strong programmers freeze up or lose points not because they don't know the material, but because they jump straight at a problem without a structured approach. Interviewers are watching your process at least as closely as your final answer. This post is a practical, repeatable framework for walking through any DSA interview question.
1. Clarify Before You Code
Resist the urge to start coding the moment you hear the problem. Ask clarifying questions out loud: What's the expected input size? Can the input contain duplicates, negative numbers, or be empty? Is the array sorted? Should the solution modify the input in place or return a new structure? These questions aren't just about covering edge cases — they also signal to the interviewer that you think carefully before acting, and sometimes the answer changes which approach is actually appropriate.
2. Start With Brute Force
Describe (and if time allows, code) the most obvious, straightforward solution first, even if you already suspect it isn't optimal. This does three things: it gives you a working solution to fall back on if you run out of time, it gives the interviewer confidence you can actually solve the problem at all, and it often reveals the exact inefficiency you need to target when optimizing. Saying "the brute force here is O(n²) because we're comparing every pair — let's see if we can do better" is a genuinely strong interview move, not a weak one.
3. Identify the Pattern
Most interview problems are variations on a small set of recurring patterns. Learning to recognize which one you're looking at is often the single biggest lever for solving a problem quickly:
- Two pointers / sliding window — searching for a subarray or pair in a sorted or contiguous structure.
- Hash map lookup — needing O(1) "have I seen this before?" checks (classic example: two-sum).
- BFS/DFS — traversing a graph or tree, or exploring "reachability."
- Backtracking — generating all valid arrangements under constraints. See our backtracking guide.
- Dynamic programming — an optimization problem with overlapping subproblems. See our dynamic programming guide.
If the brute force felt like "try everything," ask yourself which of these patterns would let you skip the obviously-wrong attempts.
4. Talk Through Complexity Out Loud
Before and after coding, state the time and space complexity of your approach, and why. Understanding Big O notation well enough to derive this on the spot — not just recite it — is what separates a confident answer from a guessed one. If you're trading memory for speed (or the reverse), say so explicitly; interviewers like hearing that you're aware of the tradeoff you're making, not just that you landed on an answer.
5. Test With Edge Cases
Once you have working code, don't declare victory — walk through it against an empty input, a single-element input, duplicates, and the largest/smallest values the constraints allow. Catching your own bug during this step, out loud, reads as careful engineering. Letting the interviewer catch it for you reads as a gap you missed.
Putting It All Together
None of these five steps requires memorizing more algorithms — they're a repeatable process you can apply to almost any problem, familiar or not. The goal isn't to arrive at the optimal solution instantly; it's to demonstrate that you can methodically work your way toward one, communicating your reasoning the entire way.
