20+ DSA Interview Questions by Topic — Quick Reference
Bookmark this table. Every row is a question you will be asked in a real interview. Difficulty, hint, and approach included so you can self-assess before moving to the detailed sections below.
| # | Question | Topic | Difficulty | Key Pattern | Approach |
|---|---|---|---|---|---|
| 1 | Two Sum | Arrays | Easy | Hash Map | Store complement in hash map, O(n) single pass |
| 2 | Maximum Subarray (Kadane's) | Arrays | Medium | Sliding Sum | Track current sum, reset when negative, O(n) |
| 3 | Product of Array Except Self | Arrays | Medium | Prefix/Suffix | Two passes: prefix products then suffix multiply, O(n) |
| 4 | Container With Most Water | Arrays | Medium | Two Pointers | Move shorter pointer inward, O(n) |
| 5 | Merge Intervals | Arrays | Medium | Sort + Greedy | Sort by start, merge overlaps, O(n log n) |
| 6 | Longest Substring Without Repeating | Strings | Medium | Sliding Window | Expand/shrink window with hash set, O(n) |
| 7 | Valid Anagram | Strings | Easy | Frequency Count | Char count comparison, O(n) |
| 8 | Reverse Linked List | Linked Lists | Easy | Pointer Reversal | Iterative prev/curr/next, O(1) space |
| 9 | Detect Cycle in Linked List | Linked Lists | Easy | Fast/Slow Pointer | Floyd's tortoise and hare, O(1) space |
| 10 | Merge Two Sorted Lists | Linked Lists | Easy | Dummy Head | Compare and attach smaller, O(n+m) |
| 11 | LRU Cache | Design | Medium | Hash + DLL | HashMap for O(1) lookup + DLL for O(1) reorder |
| 12 | Valid Parentheses | Stacks | Easy | Stack Matching | Push opens, pop on close, O(n) |
| 13 | Binary Tree Level Order | Trees | Medium | BFS Queue | Queue-based level traversal, O(n) |
| 14 | Validate BST | Trees | Medium | DFS Range | Pass valid min/max bounds down, O(n) |
| 15 | Lowest Common Ancestor | Trees | Medium | Post-order DFS | Recurse left/right, return when both found, O(n) |
| 16 | Number of Islands | Graphs | Medium | DFS/BFS Flood Fill | Sink visited cells, count components, O(m*n) |
| 17 | Course Schedule (Cycle Detection) | Graphs | Medium | Topological Sort | Kahn's BFS or DFS cycle detection, O(V+E) |
| 18 | Climbing Stairs | DP | Easy | Fibonacci | Two variables, O(n) time O(1) space |
| 19 | Coin Change | DP | Medium | Bottom-Up | 1D DP, dp[i] = min coins for amount i |
| 20 | Longest Increasing Subsequence | DP | Medium | Patience Sort | Tails array + binary search, O(n log n) |
| 21 | Edit Distance | DP | Hard | 2D Grid DP | dp[i][j] = min ops for word1[:i] to word2[:j] |
| 22 | Daily Temperatures | Stacks | Medium | Monotonic Stack | Decreasing stack stores indices, O(n) |
| 23 | Top K Frequent Elements | Heap | Medium | Bucket Sort | Count freq, bucket by count, O(n) |
| 24 | Median of Two Sorted Arrays | Binary Search | Hard | Partition | Binary search on smaller array partition, O(log min) |
Tip: Print this table and tick off each question as you master it. Aim to solve all 24 before your first interview.
Why DSA is the Gatekeeper for Product Roles
Product companies (Google, Amazon, Microsoft, Flipkart, PhonePe, Razorpay, and 200+ Indian startups) use DSA as the primary filter because it measures problem decomposition, code correctness, and scalability thinking — not syntax memorization. A 2025 Interviewing.io analysis of 50,000+ interviews found DSA rounds eliminate 68% of candidates before system design or behavioral rounds even begin.
What changed in 2025-2026: Companies shifted from "solve this LeetCode hard" to "explain the trade-off between these two approaches." They want to see thinking process > perfect code. The most successful candidates verbalize: constraint analysis → brute force → optimization → edge cases → complexity analysis → clean code. Interviewers now explicitly ask "can you walk me through your thought process?" before you write a single line.
For freshers specifically, DSA is the great equalizer. Unlike experienced candidates who can lean on system design or domain expertise, freshers are judged almost entirely on their ability to solve DSA problems under time pressure. A strong DSA performance can compensate for a non-IIT background, no internship, or a low GPA — because the code speaks for itself.
Topic Distribution & Study Priority
Analysis of 2,500+ interview experiences (Glassdoor, LeetCode Discuss, GeeksforGeeks, Striver's Sheet, Blind) across 150+ companies reveals this distribution. These percentages represent how often each topic appears in actual fresher interviews:
| Topic | Frequency | Key Patterns | Difficulty Range | Study Priority |
|---|---|---|---|---|
| Arrays & Hash Maps | 28% | Two-pointer, sliding window, prefix sum, frequency counting | Easy-Medium | ⭐⭐⭐⭐⭐ |
| Linked Lists | 18% | Reverse, cycle detection, merge, fast/slow pointer | Easy | ⭐⭐⭐⭐⭐ |
| Trees & BST | 16% | Traversals (DFS/BFS), LCA, diameter, serialization | Medium | ⭐⭐⭐⭐ |
| Dynamic Programming | 14% | Knapsack, LIS, edit distance, grid DP, memo/tabulation | Medium-Hard | ⭐⭐⭐⭐ |
| Graphs | 12% | BFS/DFS, shortest path (Dijkstra), topological sort, cycle detection | Medium-Hard | ⭐⭐⭐ |
| Stacks/Queues | 8% | Monotonic stack, next greater, valid parentheses, sliding window max | Medium | ⭐⭐⭐ |
| Tries / Heaps / Bit Manipulation | 4% | Prefix search, top-K, XOR tricks, bit counting | Medium | ⭐⭐ |
Study priority (recommended order): Arrays → Linked Lists → Trees → Stacks/Queues → DP → Graphs → Tries/Heaps/Bit. Master each topic before moving to the next. Skipping ahead creates gaps that compound during mock interviews.
Array & Hash Map Patterns — The Highest ROI
Arrays appear in 28% of all DSA questions. This is the single most important topic for freshers. Master these 5 patterns and you cover 70% of array questions asked in interviews.
Pattern 1: Two Pointer Technique
When to use: Sorted array, pair/triplet sum, palindrome checks, container with most water, removing duplicates in place.
Signal words in interview: "sorted array," "find a pair," "in-place," "without extra space."
Pattern 2: Sliding Window
When to use: Subarray/substring with condition (max sum of size k, minimum window, longest without repeating, maximum of all subarrays).
Signal words in interview: "contiguous," "consecutive," "subarray of size k," "longest substring."
Pattern 3: Prefix Sum
When to use: Range sum queries, subarray sum equals K, equilibrium index, difference arrays for range updates.
Pattern 4: Frequency Counting (Hash Map)
When to use: Anagrams, duplicates, first non-repeating element, top-K frequent elements, group by property.
Pattern 5: Prefix/Suffix Products
When to use: Product of array except self, max product subarray, plus-one number representation.
Linked List Patterns — Fast/Slow Pointer is King
18% of questions. Linked lists test your pointer manipulation skills. Three patterns solve 90% of linked list problems. The key insight: linked list problems are about pointer reassignment, not data movement.
Pattern 1: Iterative Reversal (O(1) space)
Reversing a linked list is the building block for many advanced problems: reverse in groups of k, reverse a sublist, palindrome check, reorder list. Master this first.
Pattern 2: Fast/Slow Pointer (Tortoise and Hare)
This single pattern solves three distinct problems: cycle detection, finding the middle node, and checking for palindromic structure. The speed difference creates a mathematical relationship you exploit without extra memory.
Pattern 3: Dummy Head (Merge, Remove, Reorder)
Use a dummy node to avoid special-case handling for the head. This simplifies merge, remove Nth node, and reorder operations.
Trees, BST & Graph Algorithms
Trees and graphs make up 28% of all questions combined. Trees are recursive structures — if you think recursively, tree problems become intuitive. Graphs are the generalization: any tree problem can become a graph problem.
Tree Traversals — Know All 4 Orders
Preorder (Root → Left → Right): Used for tree serialization, copying a tree, prefix expressions. Inorder (Left → Root → Right): BST in-order gives sorted order — this is how you validate a BST. Postorder (Left → Right → Root): Used for tree deletion (delete children before parent), postfix expressions. Level Order (BFS): Queue-based traversal for right side view, zigzag, level averages.
Graph Essentials — BFS/DFS, Shortest Path, Topological Sort
BFS: Shortest path in unweighted graph, level order, bipartite check. Use when you need "fewest steps." DFS: Cycle detection, topological sort, connected components, path existence. Use when you need to explore all paths. Dijkstra: Weighted shortest path using a min-heap. Topological Sort: Course schedule, alien dictionary, build systems. Use Kahn's BFS approach for clean implementation.
Dynamic Programming Patterns — Recognize, Don't Memorize
14% of questions. DP is where average candidates get separated from strong ones. The key insight: DP is pattern recognition, not brute-force memorization. If you can identify the pattern, the solution writes itself. There are exactly 5 core DP patterns that cover 90% of interview questions.
Pattern 1: 1D DP (Climbing Stairs, House Robber)
State: dp[i] depends on dp[i-1] and dp[i-2]. Use two variables instead of an array for O(1) space.
Pattern 2: 0/1 Knapsack (Subset Sum, Target Sum, Partition)
State: dp[i][w] = max value using first i items with weight w. Optimize space to 1D by iterating backwards.
Pattern 3: Longest Increasing Subsequence (LIS)
O(n log n) using patience sorting with binary search on a tails array. This is the interview-expected solution.
Pattern 4: Grid DP (Unique Paths, Min Path Sum)
State: dp[i][j] = min/max of dp[i-1][j] and dp[i][j-1] plus current cost. Build row by row or use space optimization.
Pattern 5: String DP (Edit Distance, LCS, Palindromic Substrings)
State: dp[i][j] = result for first i chars of word1 and first j chars of word2. 2D table with O(m*n) space.
Stack, Queue & Monotonic Patterns
Monotonic stacks are the single most underestimated pattern. They appear in roughly 1 in 3 medium-hard OA rounds at product companies. If you can recognize when a problem needs a monotonic stack, you jump ahead of most candidates.
Monotonic Stack — Next Greater / Smaller Element
Maintain a decreasing stack for "next greater element" and an increasing stack for "next smaller element." Each element is pushed and popped at most once, giving O(n) for all next-greater queries.
Sliding Window Maximum — Monotonic Deque
Company-Wise Question Frequency (2025-2026 Data)
Analysis of 1,500+ interview experiences from Blind, LeetCode, Glassdoor, and Striver's Discord across the 2025-2026 hiring cycle:
| Company | Top Topics | Difficulty | Coding Rounds | Key Tip |
|---|---|---|---|---|
| Graphs, DP, Trees, System Design | Medium-Hard | 4-5 | Explain trade-offs; Google cares about your thought process | |
| Amazon | Trees, Graphs, Arrays, LP | Medium | 4 | Leadership Principles equal to coding; prepare STAR stories |
| Microsoft | Arrays, Strings, Trees, Design | Medium | 3-4 | Clean code matters; follow up on edge cases proactively |
| Flipkart | Arrays, DP, Trees, Graphs | Medium | 3-4 | Indian product culture; know distributed systems basics |
| PhonePe / Paytm | Arrays, Hash Maps, Stacks, Graphs | Medium | 3 | Fintech focus; know handling of monetary precision |
| Swiggy / Zomato | Arrays, Hash Maps, Trees, DP | Medium | 3 | Real-world problems; time/space trade-offs for scale |
| Razorpay / CRED | Arrays, Graphs, DP, Design | Medium-Hard | 3-4 | High bar; expect follow-ups on complexity optimization |
| Meesho / Dream11 | Arrays, Hash Maps, Stacks, Trees | Medium | 3 | Growth mindset; know their product domain |
| Zepto / Blinkit | Arrays, Hash Maps, Graphs | Medium | 2-3 | Quick commerce; logistics/graph problems |
| TCS / Infosys / Wipro | Arrays, Linked Lists, Basic Trees | Easy-Medium | 1-2 | Aptitude + basic coding; OA speed matters most |
Most Asked DSA Questions by Company (2026)
These are the questions asked most frequently at each company based on candidate reports from the 2025-2026 hiring cycle. Prioritize these if you're targeting a specific company.
Google (L3/L4)
- Number of Islands — DFS/BFS on grid, asked in 40% of Google phone screens
- Course Schedule II — Topological sort with cycle detection
- Word Ladder — BFS on word graph with transformation rules
- Median of Two Sorted Arrays — Binary search on partition
- Serialize/Deserialize Binary Tree — Preorder with null markers
Amazon (SDE I-II)
- LRU Cache — HashMap + Doubly Linked List design question
- Binary Tree Right Side View — BFS level order traversal
- Top K Frequent Elements — Bucket sort or heap approach
- Word Break — DP on string positions with dictionary lookup
- Clone Graph — BFS/DFS with visited hash map
Microsoft
- Two Sum — Hash map complement lookup
- Valid Parentheses — Stack-based matching
- Maximum Subarray — Kadane's algorithm
- Merge Intervals — Sort + linear merge
- Lowest Common Ancestor — Post-order DFS recursion
Flipkart / Indian Product Companies
- Trapping Rain Water — Two pointers or prefix/suffix max
- 3Sum — Sort + two pointers, skip duplicates
- Number of Islands — Flood fill BFS/DFS
- Coin Change — Bottom-up DP, min coins for amount
- Largest Rectangle in Histogram — Monotonic stack
TCS NQT / Infosys / Wipro (Service Companies)
- Reverse String / Palindrome Check — String basics
- Find Missing Number — XOR or sum formula
- Check Anagram — Frequency counting
- Binary Search — Standard template on sorted array
- Merge Sorted Arrays — Two pointer merge
How to Prepare: 90-Day DSA Placement Plan
This plan assumes 2-3 hours of focused daily practice. Adjust based on your target companies and current skill level. The key principle: master one pattern deeply before moving to the next.
| Phase | Days | Focus Topics | Target Problems | Weekly Goal |
|---|---|---|---|---|
| Foundation | 1-20 | Arrays, Hash Maps, Linked Lists, Stacks/Queues, Basic Recursion | 50 Easy + 20 Medium | 10 problems/week, all patterns covered |
| Core Patterns | 21-50 | Trees, BST, Graphs (BFS/DFS), Binary Search, Two Pointers | 40 Medium | 10 problems/week, timed at 45 min each |
| Advanced | 51-75 | DP (5 patterns), Advanced Graphs (Dijkstra, Topo), Tries, Heaps | 30 Medium + 10 Hard | 10 problems/week, pattern journaling |
| Mock & Polish | 76-90 | Timed mocks, company-specific, verbal explanation practice | 5 Full Mocks + 20 Mixed | 2 mocks/week, review every error |
Daily Routine (2-3 hours)
- 45 min — 1 New Problem: Read problem → think 5 min → code → test edge cases → analyze complexity. Never look at the solution before attempting.
- 30 min — 2 Revisits: Re-solve problems from 3-5 days ago without looking at your previous solution. Retention drops 60% without spaced repetition.
- 45 min — 1 Pattern Deep Dive: Study one pattern in depth. Read 2-3 editorial approaches. Write a template you can apply to new problems.
- 30 min — Review: Update your pattern journal. Note what confused you, what clicked, and what needs more practice.
Recommended Resources
- NeetCode 150 — Best curated list, organized by pattern with video explanations
- Blind 75 — Classic 75 problems, every one appears in real interviews
- Striver's SDE Sheet — 180 problems with step-by-step approach
- LeetCode Company Tags — Filter by company for targeted practice
Common Mistakes That Cost Offers
These are the top mistakes freshers make in DSA interviews. Awareness of these alone puts you ahead of 60% of candidates.
1. Jumping to Code Without Clarifying the Problem
Ask clarifying questions: What are the constraints? Can the input be empty? Are there duplicate elements? What should I return if no solution exists? Spending 2-3 minutes clarifying saves 15 minutes of writing the wrong solution. Interviewers reward candidates who think before coding.
2. Ignoring Edge Cases
Always check: empty input, single element, all same elements, negative numbers, very large inputs, sorted vs unsorted. After writing your solution, explicitly walk through these edge cases with your interviewer. Saying "let me check the edge cases" before coding demonstrates maturity.
3. Not Analyzing Time and Space Complexity
After writing your solution, state the complexity explicitly: "This runs in O(n) time and O(1) space because..." If you don't analyze it, the interviewer assumes you don't know. If you give the wrong analysis, it's worse than not analyzing at all. Practice stating complexity out loud.
4. Using the Wrong Data Structure Without Explaining Why
If you use a hash map instead of a sorted array, explain the trade-off: "I'm using a hash map for O(1) lookups, but this costs O(n) extra space." Interviewers want to see that you understand trade-offs, not just that you can implement a solution.
5. Practicing Without a Timer
Every company OA is time-bounded. Solving problems without time pressure builds false confidence. From week 2 onwards, enforce a 30-minute hard limit per problem. If you can't solve it in 30 minutes, read the editorial, understand the approach, and re-implement from scratch. This builds the time pressure tolerance you need on interview day.
6. Memorizing Solutions Instead of Understanding Patterns
Interviewers can detect memorized solutions by changing the problem slightly. If you've truly understood the pattern, you can adapt. If you've memorized the solution, you freeze. The test: can you solve a similar problem you've never seen before? If not, you memorized, not learned.
7. Not Talking Through Your Approach
The biggest feedback from interviewers: "The candidate coded correctly but never explained their thinking." Talk through your approach before coding. Say: "I'll use a hash map to store complements because..." This demonstrates communication skills and lets the interviewer course-correct if you're heading in the wrong direction.
8. Giving Up Too Early on Hard Problems
When stuck on a Hard problem, start with the brute force. Then optimize. Saying "the brute force is O(n^2), let me think about how to optimize" is a perfectly valid approach. Many candidates freeze when they don't see the optimal solution immediately, wasting 10 minutes in silence. Brute force + optimization discussion scores better than silence + eventual optimal solution.
Time & Space Complexity Cheat Sheet
Memorize this table. You will be asked to state complexity for every solution you write. Knowing these cold means you never stumble on this follow-up question.
| Operation | Average | Worst | Space | Notes |
|---|---|---|---|---|
| Array access (by index) | O(1) | O(1) | O(1) | Contiguous memory, direct offset calculation |
| Array search (unsorted) | O(n) | O(n) | O(1) | Must check every element |
| Array search (sorted, binary) | O(log n) | O(log n) | O(1) | Halve search space each step |
| Hash map insert/search/delete | O(1) | O(n) | O(n) | Worst case with many collisions |
| Linked list insert/delete (at head) | O(1) | O(1) | O(1) | Just update pointers |
| Linked list search | O(n) | O(n) | O(1) | Must traverse from head |
| Stack/Queue push/pop | O(1) | O(1) | O(n) | Constant time operations |
| Tree traversal (DFS/BFS) | O(n) | O(n) | O(h) / O(w) | h = height, w = max width |
| BST search/insert/delete | O(log n) | O(n) | O(h) | O(n) when tree is skewed |
| Heap push/pop | O(log n) | O(log n) | O(n) | Binary heap |
| Graph BFS/DFS | O(V+E) | O(V+E) | O(V) | V = vertices, E = edges |
| Dijkstra (binary heap) | O((V+E) log V) | O((V+E) log V) | O(V) | Weighted shortest path |
| Topological Sort (Kahn) | O(V+E) | O(V+E) | O(V) | DAG ordering |
| Sorting (Timsort/Merge) | O(n log n) | O(n log n) | O(n) | Guaranteed n log n |
| Quicksort | O(n log n) | O(n²) | O(log n) | Pivot-dependent worst case |
Frequently Asked Questions
Q: Which DSA topics are most asked in fresher interviews?
A: Arrays & Hash Maps (28%), Linked Lists (18%), Trees & BST (16%), Dynamic Programming (14%), Graphs (12%), Stacks & Queues (8%). These 7 topics cover ~80% of all DSA questions. Master these first before moving to Tries, Heaps, or Bit Manipulation.
Q: How many DSA questions should I solve before interviews?
A: 150-200 curated problems: 50 Easy (learn patterns), 80 Medium (core mastery), 20 Hard (stretch goals). Focus on NeetCode 150, Blind 75, or Striver's SDE Sheet. Quality over quantity — master patterns, not memorize solutions.
Q: What is the most asked DSA question in 2026?
A: Two Sum, Reverse Linked List, Binary Tree Level Order Traversal, Valid Parentheses, and Maximum Subarray (Kadane's) are the top 5 most frequent across Google, Amazon, Microsoft, Flipkart, and Indian product companies in 2026.
Q: How to explain time complexity in interviews?
A: State it first (e.g., "O(n log n)"), then explain: "We sort (n log n) then do a single pass (n), total O(n log n). Space is O(1) extra." For recursive code, draw the recursion tree, count nodes × work per node. Always mention best/average/worst if they differ.
Q: Should I use Python or C++ for DSA interviews?
A: Use whatever you're fluent in. Python: faster to write, built-in data structures (heapq, collections), slower runtime but accepted everywhere. C++: faster runtime, STL, preferred at Google and HFT firms. Java: verbose but safe. Pick one language and master its standard library.
Q: How long does DSA prep take for product companies?
A: 8-12 focused weeks: 4 weeks on arrays/hashing/linked lists, 3 weeks on trees/graphs, 2 weeks on DP, and ongoing mock interviews from week 6. For Google or Amazon, budget the full 12 weeks. A mentor-led plan compresses this by 30-40%.
Q: Can I skip graphs for service companies?
A: For TCS NQT, Wipro, and Accenture, basic graph awareness is enough. But Infosys Power Programmer and all product company tracks require BFS/DFS fluency. Don't skip graphs if you have any product company targets.
Q: What is the best order to learn DSA topics?
A: Arrays & Hashing → Linked Lists → Stacks & Queues → Trees & BST → Graphs → Dynamic Programming → Heaps/Tries/Bit Manipulation. Each stage builds on the previous — skipping hashing makes tree and graph problems significantly harder.
Q: Is DP mandatory for fresher placements?
A: For tier-2 product companies and above, yes. DP appeared in roughly 55% of product company drives in 2025-26. For service companies (TCS NQT, Infosys, Wipro), DP is rare. Strong arrays, binary search, and graphs are sufficient for service company OAs.
Q: What are the most common DSA interview mistakes?
A: (1) Jumping to code without clarifying the problem, (2) Ignoring edge cases, (3) Not analyzing time/space complexity, (4) Using wrong data structure without explaining trade-offs, (5) Practicing without a timer, (6) Memorizing solutions instead of understanding patterns, (7) Not talking through your approach.