Coding Interview Preparation: DSA Questions, Patterns and Practice
Crack coding interviews with DSA questions, problem-solving patterns and AI mock interviews that test how you explain your approach — for freshers and SDEs.
Coding interviews test whether you can turn a problem into working, efficient code while explaining your thinking. They are used for software engineering roles at almost every level, from campus hiring to senior positions, and they follow a surprisingly predictable structure.
This guide covers the data structures and algorithm patterns that come up most often, a step-by-step method for solving problems live, sample questions with approaches, and a practical study plan.
What interviewers evaluate in a coding round
- Problem solving: can you break the problem down and find an approach, not just recall a memorised solution?
- Communication: do you explain your thinking, ask clarifying questions and respond to hints?
- Code quality: is the code correct, readable and sensibly structured?
- Complexity analysis: can you state and justify time and space complexity?
- Testing: do you check edge cases and walk through an example?
A step-by-step method for any coding question
- Restate the problem in your own words and confirm the input and output.
- Ask clarifying questions: input size, duplicates, negative numbers, empty input, sorted or not.
- Work through one or two small examples by hand.
- Describe a brute-force solution and its complexity — this proves you understand the problem.
- Look for a better approach using a known pattern (see below), and explain the trade-off.
- Write the code, talking through each part.
- Test with your examples and edge cases, then fix bugs calmly.
- State the final time and space complexity.
The data structures you must know
- Arrays and strings — indexing, slicing, in-place updates.
- Hash maps and sets — constant-time lookup; the most common optimisation tool.
- Stacks and queues — matching brackets, monotonic stacks, BFS.
- Linked lists — reversal, cycle detection, merging.
- Trees and binary search trees — traversals, height, lowest common ancestor.
- Heaps (priority queues) — top-K problems, merging sorted lists, scheduling.
- Graphs — adjacency lists, BFS, DFS, topological sort.
- Tries — prefix search and autocomplete.
The 12 problem patterns that cover most questions
Two pointers
Use two indices moving towards each other or in the same direction. Classic uses: pair sum in a sorted array, removing duplicates, checking palindromes.
Sliding window
Maintain a window over a sequence and expand or shrink it. Classic uses: longest substring without repeating characters, maximum sum of a subarray of size K.
Hashing for lookups
Trade memory for speed by storing seen values. Classic use: Two Sum — store each number’s index and check whether target minus the current number already exists, giving O(n) time.
Prefix sums
Pre-compute running totals so range sums take constant time. Classic use: number of subarrays that sum to K.
Binary search
Not only for sorted arrays — also for searching the answer space, such as the minimum capacity needed to ship packages within D days.
Fast and slow pointers
Detect cycles in linked lists or find the middle node in one pass.
Stack and monotonic stack
Valid parentheses, next greater element, daily temperatures, largest rectangle in a histogram.
Tree traversal (DFS and BFS)
Recursion for depth, path sums and subtree checks; BFS for level-order traversal and shortest paths in unweighted trees.
Graph traversal and topological sort
Number of islands, course schedule, detecting cycles in dependencies.
Heaps and top-K
K most frequent elements, merge K sorted lists, kth largest element.
Backtracking
Generate subsets, permutations and combinations; solve constraint problems like N-Queens.
Dynamic programming
Break a problem into overlapping subproblems. Start with recursion plus memoisation, then convert to a table if needed. Classic uses: climbing stairs, coin change, longest common subsequence, house robber.
Sample coding interview questions by level
Entry level and campus interviews usually focus on arrays, strings, hash maps and basic recursion: reverse a string, find duplicates, check for anagrams, Two Sum, merge two sorted arrays, and FizzBuzz-style logic.
Mid-level interviews add trees, graphs, heaps and medium dynamic programming: level-order traversal, number of islands, top-K frequent elements, longest increasing subsequence, LRU cache design.
Senior interviews often combine a medium or hard algorithm question with discussion of production concerns — concurrency, memory usage, API design and how you would test the code.
A 6-week coding interview study plan
- Week 1: Arrays, strings, hash maps, two pointers. Solve 15–20 easy problems.
- Week 2: Sliding window, prefix sums, stacks and queues.
- Week 3: Linked lists, binary search, trees (DFS and BFS).
- Week 4: Graphs, topological sort, heaps.
- Week 5: Backtracking and dynamic programming.
- Week 6: Mixed timed practice and full mock interviews with an interviewer or AI.
- Throughout: after each problem, write down the pattern and the key insight. Reviewing patterns beats solving hundreds of random problems.
Common reasons candidates fail coding interviews
- Coding in silence — the interviewer can’t give credit for thinking they can’t hear.
- Jumping into code before agreeing on the approach.
- Ignoring edge cases: empty input, a single element, duplicates, overflow.
- Not knowing the complexity of their own solution.
- Getting stuck and freezing instead of falling back to brute force and improving it.
Practise coding interviews out loud
Solving problems alone builds knowledge; explaining them under time pressure builds interview skill. InterviPrep’s AI interviewer asks you to talk through your approach, challenges your choices with follow-up questions and scores your explanation, so you can practise the communication half of the coding round as well as the algorithms.
Frequently asked questions
Which programming language should I use in a coding interview?
Use the language you are most fluent in, unless the role requires a specific one. Python is popular for its concise syntax, while Java and C++ are also widely accepted.
How many problems should I solve before interviews?
Quality matters more than quantity. Around 100–150 well-understood problems covering all the major patterns is enough for most candidates, especially if you review the pattern behind each one.
Are coding interviews the same for freshers and experienced engineers?
The format is similar, but difficulty and expectations rise with seniority. Experienced candidates are expected to write cleaner code faster and to discuss trade-offs and production concerns.
What if I can’t solve the problem completely?
Keep communicating. A clear brute-force solution, a well-explained optimisation idea and good testing can still earn a positive result, even if the final code is incomplete.
Start your preparation journey
Join thousands of professionals using AI to master their interviews and land their dream jobs.
Start Free Trial