DSA
DSA Interview Questions for Freshers: Top 30 Patterns with Solutions
Master DSA interview questions for campus placements — arrays, strings, trees, graphs, DP. Top 30 patterns with approach hints, complexity, and links to practice problems.
DSA is the core of every coding interview. Here are the top 30 patterns — from two pointers to dynamic programming — that appear in TCS, Amazon, Microsoft, and Google interviews.
Why patterns matter more than memorizing problems
Most coding interview questions are variations of 15-20 core patterns. If you recognize the pattern, you can solve any variation — even under pressure.
Companies like Amazon and Microsoft don't expect you to memorize 500 LeetCode problems. They expect you to recognize the pattern and apply it to a new problem in 30 minutes.
Array patterns (most frequently asked)
Two pointers — pair sum, three sum, container with most water. Start with sorted arrays, move pointers based on sum comparison.
Sliding window — maximum subarray sum K, longest substring without repeating characters. Maintain a window [left, right] and shrink/expand based on condition.
Prefix sum — range sum queries, equilibrium index. Precompute cumulative sums for O(1) range queries.
Kadane's algorithm — maximum subarray sum. Track current max and global max as you iterate.
Dutch national flag — sort 0s, 1s, 2s in-place. Three-way partitioning.
String patterns
Hash map counting — character frequency, anagram check. Use Map or object for O(n) lookups.
Palindrome — expand from center, or reverse and compare. Two-pointer approach from both ends.
String matching — KMP algorithm, Rabin-Karp. Know at least one efficient string search algorithm.
Anagram grouping — sort each string as key, group by sorted key.
Tree and graph patterns
BFS / DFS — tree traversal, graph traversal. Use queue for BFS, stack/recursion for DFS.
Binary search tree — search, insert, delete. Know the BST property and in-order traversal.
Tree DP — diameter of binary tree, maximum path sum. Post-order traversal with return values.
Graph shortest path — Dijkstra for weighted, BFS for unweighted. Know when to use each.
Topological sort — course schedule, task dependency. Use DFS or Kahn's algorithm (BFS-based).
Dynamic programming patterns
1D DP — Fibonacci, climbing stairs, house robber. Identify subproblems and overlapping computations.
2D DP — longest common subsequence, edit distance, 0/1 knapsack. Build a table from base cases.
DP on arrays — maximum subarray, jump game. Track state at each position.
DP on strings — longest palindromic substring, word break. Process substrings from shortest to longest.
Bitmask DP — traveling salesman, subset sum. Use bitmasks when state includes which elements are used.
Linked list and stack patterns
Fast/slow pointers — detect cycle, find middle, merge point. Floyd's algorithm.
Reverse linked list — iterative and recursive. Fundamental operation tested everywhere.
Merge sorted lists — two-pointer merge. Extension: merge K sorted lists with heap.
Monotonic stack — next greater element, largest rectangle in histogram. Maintain a stack of indices.
Valid parentheses — stack-based matching. Extension: generate all valid parentheses combinations.
Company-wise DSA expectations
TCS / Wipro / Cognizant: Easy/medium arrays, strings, basic sorting. Check TCS coding questions on Apply PYQs.
Amazon / Microsoft: Medium arrays, trees, graphs, DP. 2-3 problems in OA. Check Amazon OA questions on Apply.
Google / Meta: Hard problems, often 2 patterns combined. System design may accompany coding.
Goldman Sachs / JP Morgan: Medium DP + array problems. Focus on correctness over optimization.
How to practice DSA for placements
Start with NeetCode Blind 75 — covers all 15 core patterns with video explanations.
Practice on LeetCode with company tags — filter by your target company.
Solve under timed conditions: 30 minutes for easy, 45 for medium, 60 for hard.
Keep a pattern notebook: write the pattern name, approach, and time complexity for each problem.
Use Apply's company PYQs at /pyqs to see exactly which DSA problems each company asked in previous years.
After DSA: interview preparation
DSA clears the coding round. The interview round tests communication, project knowledge, and behavioral fit.
Practice with Apply's AI mock interview at /mock-interview — it simulates real interview conditions with voice questions and scored feedback.
