DSA Interview Questions: Topic-wise Question Banks
Last updated 2026-11-19
Data structures and algorithms questions decide most coding rounds, whether they appear in an online test, a whiteboard-style interview or a live pair-programming session. The guides in this section split the subject by topic, such as arrays, strings, hashing, linked lists, trees, graphs and dynamic programming, and work through the patterns that recur within each.
The goal is pattern recognition. Almost every medium-level question is a known pattern wearing a new story. If you can name the pattern, state its complexity and write it without hesitation, you will solve unfamiliar problems far faster than someone who has only memorised solutions.
Learn patterns before volume
Take one topic at a time and finish its bank before starting another. Within a topic, the questions are ordered from easy to hard so that you meet the basic pattern first and its harder variations later. Sliding window, two pointers, prefix sums, binary search on the answer and monotonic stacks each unlock a family of problems.
After each question, write one sentence naming the pattern and the signal in the problem statement that suggests it. Sorted input hints at two pointers or binary search. A contiguous subarray with a constraint hints at a sliding window or prefix sums. Counting or deduplication hints at hashing.
Always state complexity
Interviewers expect time and space complexity with every solution. Practise saying it out loud, including what n means. A solution that is correct but whose complexity you cannot justify will score lower than a slightly slower one you can analyse clearly. Each worked answer here states both so you can compare your own analysis against it.
A sensible order of topics
- Arrays and strings, including sorting and basic hashing.
- Linked lists, stacks and queues.
- Recursion and backtracking.
- Trees and binary search trees, then heaps.
- Graphs: traversal, shortest paths and connected components.
- Dynamic programming, starting with one-dimensional states.
- Bit manipulation and math tricks, which are short and often examined.
Practising under test conditions
Online tests usually give two or three problems in 60 to 90 minutes, so reading speed and edge case discipline matter as much as algorithms. Set a timer, write in the language you will actually use, and test your code on empty input, a single element, duplicates and the largest allowed size before you call it done.
Choosing a language
Use one language consistently. Python is compact and quick to write, while Java and C++ are common in company tests and give you stronger control over performance. Whatever you pick, know its standard collections well. The programming language guides cover the language-specific questions that follow from the algorithms.
All 50 guides in this section
- Array interview questions with worked solutionsTen array interview problems from easy to hard, with in-place techniques, complexity and edge cases, plus Python and Java code for each.
- Backtracking interview questions with worked solutionsTen backtracking problems: subsets, permutations, combinations, parentheses, word search, N-Queens and Sudoku, with code and complexity.
- BFS (Breadth-First Search) Interview QuestionsBreadth-first search interview questions: shortest paths in grids, multi-source BFS, word ladder, 0-1 BFS and bitmask BFS, with Python and Java code.
- Binary search interview questions with worked solutionsTen binary search problems: bounds, rotated arrays, peaks, search on the answer and the median of two sorted arrays, with code and complexity.
- Binary Search Tree Interview Questions and AnswersBST interview questions with worked solutions: search, insert, delete, validate, kth smallest, LCA, iterator, with Python and Java code and complexity.
- Binary Tree Interview Questions and AnswersThirteen binary tree interview problems from max depth to max path sum, with approach, Python and Java code, complexity and edge cases for each.
- Bit manipulation interview questions with worked solutionsTen bit manipulation problems: set bits, power of two, XOR tricks, reverse bits, bitmask subsets and sum without plus, in Python and Java.
- Bitmask DP Interview QuestionsBitmask DP interview questions: subsets, partition into k sums, can I win, work sessions, travelling salesman, hats and skills, in Python and Java.
- Cyclic sort pattern interview questions with worked solutionsTen cyclic sort problems on arrays of 1 to n: missing and duplicate numbers, set mismatch, minimum swaps and first K missing, with code.
- DFS (Depth-First Search) Interview QuestionsDepth-first search interview questions: islands, flood fill, word search, Pacific Atlantic, longest increasing path and safe states, with Python and Java.
- Dijkstra and Shortest Path Interview QuestionsDijkstra and shortest path interview questions: network delay, minimax paths, counting shortest paths, K stops, Bellman-Ford, in Python and Java.
- Divide and Conquer Interview QuestionsDivide and conquer interview questions: merge sort, quickselect, inversions, median of two arrays, closest pair and more, in Python and Java.
- Dynamic Programming Interview QuestionsDynamic programming interview questions with worked solutions: stairs, robber, Kadane, coin change, decode ways, word break and stock states, Python and Java.
- Edit Distance and String DP Interview QuestionsEdit distance and string DP interview questions: Levenshtein, edit script, palindromes, wildcard and regex matching, KMP, in Python and Java.
- Fast and slow pointers interview questions with solutionsTen fast and slow pointer problems: cycle detection and start, middle node, palindrome list, happy number, duplicate and circular array loop.
- Fenwick Tree (Binary Indexed Tree) Interview QuestionsFenwick tree (binary indexed tree) interview questions: range sums, inversions, range updates, kth element, 2D BIT and offline queries, in Python and Java.
- Graph Interview Questions and AnswersGraph interview questions with worked solutions: connectivity, cycle detection, bipartite check, clone graph, Floyd-Warshall and bridges, in Python and Java.
- Greedy algorithm interview questions with worked solutionsTen greedy algorithm interview problems: cookies, jump game, gas station, task scheduler, candy and refuelling stops, with proofs and code.
- Grid and Matrix DP Interview QuestionsGrid DP interview questions with worked solutions: unique paths, minimum path sum, maximal square and rectangle, dungeon game, in Python and Java.
- Hashing interview questions with worked solutionsTen hash map and hash set interview problems from Two Sum to LRU cache, with Python and Java code, complexity and edge cases for each.
- Heap and Priority Queue Interview QuestionsHeap and priority queue interview problems with worked solutions: top K, merge K lists, running median, meeting rooms, with Python and Java code.
- Interval DP Interview QuestionsInterval DP interview questions: burst balloons, matrix chain, cut a stick, strange printer, merge stones, game DP and palindromes, Python and Java.
- Interval interview questions with worked solutionsTen interval problems: meeting rooms, non-overlapping intervals, arrows, car pooling, event scheduling and weighted jobs, with code and complexity.
- Kadane algorithm interview questions with worked solutionsTen maximum subarray problems solved with Kadane algorithm: circular, product, deletion, absolute sum and 2D variants, in Python and Java.
- KMP and string matching interview questions with solutionsTen string matching problems: KMP prefix function, pattern search, repeated patterns, Rabin-Karp, shortest palindrome and Z-function, with code.
- Knapsack DP Interview QuestionsKnapsack DP interview questions: 0/1 and unbounded knapsack, subset sum, partition, target sum, ones and zeroes and bounded items, in Python and Java.
- Linked list interview questions with worked solutionsTen linked list interview problems, from reversing a list to k-group reversal and merging k lists, with Python and Java code and edge cases.
- Longest Common Subsequence (LCS) Interview QuestionsLongest common subsequence interview questions: LCS length and string, substring, palindromic subsequence, supersequence and more, in Python and Java.
- Longest Increasing Subsequence (LIS) Interview QuestionsLIS interview questions: O(n^2) and O(n log n) solutions, printing the sequence, counting, bitonic, envelopes and variants, in Python and Java.
- LRU Cache and Design Data Structure Interview QuestionsDesign data structure interview questions: LRU and LFU cache, min stack, randomized set, time map, rate limiter and more, in Python and Java.
- Math and number theory interview questions with solutionsTen math interview problems: gcd, primes, sieve, factorisation, factorial zeroes, modular exponentiation and nCr mod p, in Python and Java.
- Matrix interview questions with worked solutionsTen 2D array and matrix interview problems: rotate, spiral, set zeroes, search, islands, sudoku, game of life and kth smallest, with code.
- Merge intervals pattern questions with worked solutionsEleven merge-intervals pattern problems: merge, insert, intersections, unions, gaps and bold tags, with Python and Java code and edge cases.
- Minimum Spanning Tree Interview QuestionsMinimum spanning tree interview questions: Kruskal, Prim, connecting points, water distribution, critical edges and uniqueness, in Python and Java.
- Monotonic stack interview questions with worked solutionsTen monotonic stack problems: next greater element, daily temperatures, histogram rectangles and lexicographic stack tricks, in Python and Java.
- Prefix sum interview questions with worked solutionsTen prefix sum problems, from range queries and pivot index to subarray sum K and difference arrays, with Python and Java solutions.
- Queue and deque interview questions with worked solutionsTen queue and deque problems: circular queue, stack from queues, BFS on grids and trees, and monotonic deque tricks, in Python and Java.
- Recursion interview questions with worked solutionsEleven recursion interview questions: memoisation, fast power, Tower of Hanoi, tree recursion, flood fill and divide and conquer, with code.
- Segment Tree Interview QuestionsSegment tree interview questions: range sum and min, kth smallest, inversions, LIS, lazy propagation and max subarray updates, in Python and Java.
- Sliding window interview questions with worked solutionsTen sliding window problems, fixed and variable size, from maximum sum subarray to minimum window substring, with code and complexity.
- Sorting algorithm interview questions with worked solutionsEleven sorting interview questions: bubble, insertion, merge, quick and heap sort, counting sort, quickselect and custom comparators, in Python and Java.
- Stack interview questions with worked solutionsTen stack interview problems from valid parentheses and min stack to calculators and longest valid parentheses, with code and complexity.
- String interview questions with worked solutionsTen string interview problems, from palindromes and anagrams to multiply strings and decode string, with Python and Java code and complexity.
- Top K elements interview questions with worked solutionsTen top-K problems solved with heaps, buckets and binary search: kth largest, frequent elements, closest points, median stream and more.
- Topological Sort Interview QuestionsTopological sort interview questions: course schedule, Kahn and DFS orders, alien dictionary, critical path and minimum height trees, in Python and Java.
- Tree DP Interview QuestionsTree DP interview questions: house robber III, cameras, coins, independent set, diameter, rerooting and largest BST subtree, in Python and Java.
- Tree Traversal Interview QuestionsTree traversal interview questions: iterative inorder, preorder and postorder, Morris, zigzag, vertical order, rebuild from traversals, Python and Java.
- Trie (Prefix Tree) Interview QuestionsTrie (prefix tree) interview questions: implement a trie, wildcard search, word search II and maximum XOR, with Python and Java code and complexity.
- Two pointers interview questions with worked solutionsTen two pointers problems from Two Sum II to 4Sum, covering sorted arrays, palindromes and in-place scans, with Python and Java solutions.
- Union-Find (Disjoint Set Union) Interview QuestionsUnion-find (disjoint set union) interview questions: redundant connection, accounts merge, islands II and more, with Python and Java code and complexity.
Frequently asked questions
How many DSA problems do I need to solve for placements?
There is no magic number. Covering every topic with a few well-understood problems each, and being able to redo them from scratch, is worth more than a large count of half-remembered solutions.
Which language is best for DSA interviews?
The one you can write fastest without syntax errors. Python is shortest, Java and C++ are widely accepted everywhere. Switching language late in preparation usually costs more time than it saves.
Should I memorise solutions?
Memorise patterns and their complexity, not code. Interviewers change constraints, and a memorised solution does not adapt.
Where do I practise after reading a topic bank?
Re-solve each question without looking, then try similar problems on any practice platform. The how-to guides under how-to explain how common test platforms behave.