Data structures & algorithms
Top DSA Interview Questions & Topic Map

Most candidates study DSA randomly: random problems, random tags, random YouTube videos. Interview loops are not random — they sample from a skewed distribution of topics. The chart below is an illustrative composite (typical product-company and strong campus OAs): it shows relative how often each theme appears, not a guarantee for one company on one day.
Higher bars = more interview surface area across a typical prep cohort. Use it to order your revision, not to skip entire topics.
How to read the topic landscape
Arrays & hashing sit on top because they are the default substrate for OAs and many round-1 problems. Trees and graphs spike at product companies and strong intern pipelines. DP is asked less often by volume but is a high-variance filter: when it shows up, unprepared candidates collapse quickly.
DSA Learning Roadmap
Step-by-step path from fundamentals to interview readiness. Each stage unlocks the next — do not jump to dynamic programming before you can implement BFS on a graph without hints.

Beginner
Build problem-solving basics, learn time and space complexity notation, and practice simple brute-force problems before pattern templates.
Arrays
Master linear data structures — prefix sum, sliding window, and two pointers cover the majority of OA round-1 problems.
Hashing
Learn hash tables, maps, and sets. Frequency maps and counting patterns unlock two-sum variants and anagram problems.
Linked Lists
Handle dynamic structures with fast/slow pointers — reverse, merge, detect cycle, and remove nth node from end.
Trees
Explore hierarchical structures — traversals, BST validation, LCA, diameter, and level-order BFS on trees.
Graphs
Solve connected-component and shortest-path problems with BFS, DFS, topological sort, and union-find.
Dynamic Programming
Tackle optimization with memoization vs tabulation — start 1D (stairs, robber, coin change) before 2D (LCS, edit distance).
Mock Interviews
Simulate real loops with company-wise question sets, timed OAs, and spoken complexity analysis under pressure.
Interview Ready
Revise high-frequency problems, revisit weak patterns, and stay consistent — readiness is cumulative, not last-minute cramming.
Company-wise DSA Expectations
Calibrate difficulty and depth to your target company — studying Google-level DP for a TCS NQT OA wastes time; skipping graphs for Amazon SDE guarantees a filter.
| Company | Difficulty | Focus Areas | Expected Level |
|---|---|---|---|
| TCS | Easy–Medium | Arrays, strings, basic sorting, aptitude-heavy OAs | Fresher / 0–1 yr (NQT pipeline) |
| Infosys | Easy–Medium | Arrays, hashing, linked lists, InfyTQ MCQs + coding | Fresher / 0–1 yr (InfyTQ, HackWithInfy) |
| Wipro | Easy–Medium | Arrays, strings, basic DS, logic & verbal sections | Fresher / 0–1 yr (Elite NTH, campus drive) |
| Accenture | Easy–Medium | Arrays, pseudocode, DBMS/SQL MCQs, coding basics | Fresher / 0–1 yr (ASE track) |
| Freshworks | Medium | JavaScript DSA, arrays, hashing, moderate OA problems | 1–3 yr (Frontend / SWE product roles) |
| Amazon | Hard | Trees, graphs, DP, two pointers, Bar Raiser depth | SDE I–II (OA + 2 live coding rounds) |
| Microsoft | Medium–Hard | Arrays, trees, graphs, binary search, system design at senior | SDE I–II (OA + coding loop) |
| Hard | Graphs, DP, trees, advanced optimization, Googleyness | L3–L4 (phone screen + onsite coding) |
DSA Patterns
Interview problems repeat as patterns, not isolated puzzles. Learn to recognize the pattern first, then map it to a template — interviewers grade pattern recognition as much as implementation.
Sliding Window
When to use: Contiguous subarray/substring problems with a running constraint — max sum, longest unique substring, fixed-size window.
Common problems:
- Longest substring without repeating characters
- Minimum window substring
- Max sum subarray of size k
- Fruit into baskets
Two Pointers
When to use: Sorted arrays, palindrome checks, pair-sum problems, or squeezing window boundaries from both ends.
Common problems:
- Two sum II (sorted)
- Container with most water
- 3Sum
- Valid palindrome
Prefix Sum
When to use: Range sum queries, subarray sum equals k, cumulative frequency tracking over indices.
Common problems:
- Subarray sum equals k
- Range sum query
- Continuous subarray sum
- Product of array except self
Binary Search
When to use: Sorted data, monotonic answer spaces, or “find minimum/maximum feasible value” optimization problems.
Common problems:
- Search in rotated sorted array
- Koko eating bananas
- Find minimum in rotated array
- Median of two sorted arrays
DFS
When to use: Tree/graph traversal, connected components, path exploration, backtracking branches where depth-first is natural.
Common problems:
- Number of islands
- Path sum
- Clone graph
- Word search
BFS
When to use: Shortest path in unweighted graphs, level-order traversal, minimum steps/spread problems.
Common problems:
- Rotten oranges
- Word ladder
- Binary tree level order
- Shortest path in binary matrix
Backtracking
When to use: Generate all combinations/permutations, constraint satisfaction, explore and undo choices.
Common problems:
- Subsets
- Permutations
- Combination sum
- N-Queens
- Word search II
Greedy
When to use: Local optimal choices lead to global optimum — scheduling, interval merging, Huffman-style problems.
Common problems:
- Merge intervals
- Jump game
- Non-overlapping intervals
- Assign cookies
Dynamic Programming
When to use: Overlapping subproblems + optimal substructure — counting paths, knapsack family, sequence alignment.
Common problems:
- Climbing stairs
- House robber
- Coin change
- Longest increasing subsequence
- Edit distance
Interview Patterns vs Topics
Patterns are reusable templates; topics are the data structures they apply to. Use this map to plan revision — when you drill sliding window, prioritize array and string problems first.
| Pattern | Relevant Topics |
|---|---|
| Sliding Window | Arrays, Strings, Hashing |
| Two Pointers | Arrays, Linked Lists, Strings |
| Prefix Sum | Arrays, Hashing |
| Binary Search | Arrays, Trees, Heaps |
| DFS | Trees, Graphs, Backtracking |
| BFS | Graphs, Trees, Matrices |
| Backtracking | Trees, Graphs, Arrays, Strings |
| Greedy | Arrays, Graphs, Heaps, Intervals |
| Dynamic Programming | Arrays, Strings, Trees, Graphs |
Top 50 Must-Know DSA Problems
These 50 problems cover the highest-frequency patterns across campus OAs and product company loops. Solve each once, then re-solve after 5–7 days without looking at solutions. Focus on pattern recognition, not memorizing code.
Arrays (9 problems)
- Two Sum
- Best Time to Buy and Sell Stock
- Product of Array Except Self
- Maximum Subarray (Kadane)
- Merge Intervals
- Rotate Array
- Find Missing Number
- Container With Most Water
- Trapping Rain Water
Hashing (8 problems)
- Group Anagrams
- Valid Anagram
- Longest Consecutive Sequence
- Subarray Sum Equals K
- Top K Frequent Elements
- First Missing Positive
- Longest Substring Without Repeating Characters
- Isomorphic Strings
Linked Lists (7 problems)
- Reverse Linked List
- Merge Two Sorted Lists
- Linked List Cycle
- Remove Nth Node From End
- Reorder List
- Add Two Numbers
- Copy List with Random Pointer
Trees (9 problems)
- Maximum Depth of Binary Tree
- Invert Binary Tree
- Diameter of Binary Tree
- Lowest Common Ancestor of BST
- Validate Binary Search Tree
- Binary Tree Level Order Traversal
- Serialize and Deserialize Binary Tree
- Path Sum III
- Construct Binary Tree from Preorder and Inorder
Graphs (8 problems)
- Number of Islands
- Course Schedule
- Rotting Oranges
- Word Ladder
- Clone Graph
- Pacific Atlantic Water Flow
- Network Delay Time
- Redundant Connection
Dynamic Programming (9 problems)
- Climbing Stairs
- House Robber
- Coin Change
- Longest Increasing Subsequence
- Word Break
- Unique Paths
- Edit Distance
- Maximum Product Subarray
- Partition Equal Subset Sum
Arrays, strings & hashing
Canonical patterns: frequency maps, prefix sums, sorting as preprocessing, index mapping.
- Two sum / k-sum family (hash map or sort + two pointers).
- Longest substring without repeat / at most k distinct (sliding window).
- Subarray sum equals k (prefix sum + hash map).
- Merge intervals and meeting-room style scheduling.
Two pointers & sliding window
Often combined with arrays or strings. Interviewers use these to test whether you can maintain invariants while moving indices — not whether you memorized a template.
- Container with most water, trapping rain water (two pointers from ends).
- Minimum window substring / smallest subarray with sum ≥ target.
- Fast/slow pointer for cycle detection (also linked lists).
Linked lists
- Reverse linked list (iterative + recursive).
- Merge two sorted lists, add two numbers represented as lists.
- Detect cycle (Floyd), find intersection of two lists.
Trees & BST
- Traversals, height/depth, balanced tree check, diameter of binary tree.
- LCA in BST vs LCA in binary tree.
- Path sum variants, serialize/deserialize tree.
Graphs
- Number of islands, rotten oranges, word ladder (BFS layering).
- Course schedule / topological sort.
- Connected components, DFS on grid vs adjacency list.
Dynamic programming
Start with 1D DP (climbing stairs, house robber, coin change) before 2D (LCS, edit distance). Interviewers often accept O(n²) with clear state definition over a rushed “optimized” solution you cannot explain.
Binary search & heaps
- Binary search on answer space (Koko eating bananas, split array largest sum).
- Median from data stream, merge k sorted lists, top k frequent elements.
Interview Communication
Strong DSA knowledge without spoken communication loses offers. Product company panels explicitly grade how you think aloud — practice narration as seriously as problem-solving.
Explaining your approach
Before coding, restate the problem, confirm constraints, and walk through 1–2 examples including edge cases. Interviewers grade whether you de-risk ambiguity before writing code.
Tip: Use a 30-second outline: brute force → bottleneck → optimized approach. Ask “Does this match what you had in mind?” before implementing.
Complexity discussion
Always state time and space complexity after your solution. Explain why — count nested loops, hash map lookups, recursion depth — not just Big-O labels.
Tip: Compare brute force vs optimized complexity aloud. Example: “Hash map brings this from O(n²) to O(n) with O(n) extra space.”
Optimization discussion
Interviewers often ask “Can you do better?” even after a correct answer. Know trade-offs: time vs space, preprocessing vs query, iterative vs recursive.
Tip: If stuck, say what you would try next — sorting, two pointers, prefix sums — rather than going silent.
Interviewer communication
Think aloud during coding. Flag when you are stuck, state assumptions, and recover gracefully from bugs. Silence reads as inability, not deep thinking.
Tip: Run a dry-run on your example before saying “done.” Verbalize each line’s purpose as you write it.
Prep timeline: three tracks in parallel
The line chart below is illustrative: it shows how readiness might grow if you keep core DS, pattern depth, and mock interviewsmoving together. Mocks that start too late produce a flat green curve in real life — don't wait until week 8 to speak out loud.
Y-axis: self-rated readiness 1–10. Your curve will differ — use the shape as a planning reminder, not a prediction.
Mistakes that cost offers
- Only coding in silence. Interviews grade communication. Narrate assumptions, complexity, and trade-offs.
- Skipping complexity. Always state time and space; invite follow-ups on optimization.
- One-shot practice. Re-solve the same problem after 5–7 days (spaced repetition).
- Ignoring OAs. Many Indian campus pipelines filter hard on timed OAs — practice under timer and partial scoring mindset.
Related Preparation Guides
Cross-train with role and company-specific question banks. DSA overlaps heavily with software engineer loops — pair this guide with company hubs for your target employers.
Frequently Asked Questions
How many DSA problems should I solve before interviews?
Aim for 150–200 quality problems across patterns rather than 500 random solves. Cover top 50 must-know problems deeply, then expand by weak patterns. Re-solve key problems after 5–7 days for retention.
Which DSA topic is most important for campus placements?
Arrays and hashing appear most frequently in Indian campus OAs (TCS NQT, Infosys InfyTQ, Wipro Elite). Master two pointers, sliding window, and prefix sum before moving to trees and graphs.
Is LeetCode enough for DSA interview prep?
LeetCode is a strong practice platform but not sufficient alone. Pair problem-solving with timed OAs, spoken mock interviews, and company-specific pattern review. Communication and complexity analysis matter as much as AC rate.
How long does DSA prep take for product companies?
Most candidates need 8–12 focused weeks: 4 weeks on arrays/hashing/lists, 3 weeks on trees/graphs, 2 weeks on DP, and ongoing mocks from week 6 onward. Amazon and Google typically require the full timeline.
Do service companies ask hard DSA questions?
TCS, Infosys, Wipro, and Accenture focus on easy–medium arrays, strings, and basic logic in OAs. Live technical rounds may add linked lists or simple trees but rarely hard DP or graph optimization.
Should I learn DSA in Java or C++?
Use whichever language you will code in during interviews. Java and C++ are both common in India campus drives. Python is acceptable at many product companies but confirm with your target company first.
What is the best order to learn DSA topics?
Follow the learning roadmap: Beginner → Arrays → Hashing → Linked Lists → Trees → Graphs → Dynamic Programming → Mock Interviews → Interview Ready. Each stage builds on the previous — skipping hashing makes tree and graph problems harder.
How important is dynamic programming for fresher interviews?
DP is less frequent in service-company OAs but is a high-variance filter at Amazon, Google, and Microsoft. Learn 1D DP (climbing stairs, house robber, coin change) before 2D DP (LCS, edit distance).
How do I practice DSA under time pressure?
Simulate OAs weekly: 2–3 problems in 60–90 minutes with no hints. Use a timer for individual problems (25–35 min). Track which patterns slow you down and drill those specifically.
What DSA patterns appear most in Amazon interviews?
Amazon SDE loops heavily test trees, graphs, BFS/DFS, two pointers, and medium DP. OA filters on arrays and strings first — strong OA performance is required before live coding rounds.
Can I skip graphs if I am targeting service companies?
For TCS/Wipro/Accenture campus drives, basic graph awareness is enough. Infosys Power Programmer and all product company tracks require BFS/DFS fluency — do not skip graphs if you have product company targets.
How do I explain time complexity in interviews?
Count operations as a function of input size n. State best, average, and worst case when relevant. Tie complexity to your data structures: “Hash map lookups are O(1), so the overall loop is O(n).” Always mention space complexity too.
Generate role-shaped question sets with our free interview question generator, tighten behavioral stories with the STAR answer builder, and line up full sessions with InterviewEra mock interviews.
Turn topics into spoken practice
Upload your resume, run AI mock interviews, and get rubric-style feedback — not just more random problems.
Start free practice