150+ DSA Interview Questions and Coding Problems for Freshers and Experienced Developers
Data Structures and Algorithms, commonly known as DSA, are among the most important topics for software development interviews. Whether you are a fresher preparing for your first technical interview or an experienced developer looking to move into a better role, DSA can help you demonstrate your programming knowledge, logical thinking, and problem-solving ability.
Technical interviewers use DSA questions to understand how candidates approach unfamiliar problems. They may ask you to write code, explain an algorithm, compare two approaches, analyze time complexity, or optimize an existing solution.
This guide contains more than 150 DSA interview questions and coding problems with simple explanations. The questions progress from beginner-friendly concepts to intermediate and advanced topics, making this a useful revision resource for interview preparation at My Learn Nest in 2026.
DSA Interview Questions for Freshers
1. What is DSA?
DSA stands for Data Structures and Algorithms. A data structure is a way of organizing and storing data, while an algorithm is a step-by-step method for solving a problem. Together, they help developers create efficient and scalable programs.
2. Why is DSA important for software interviews?
DSA helps interviewers evaluate a candidate’s logical thinking, programming ability, optimization skills, and understanding of computational efficiency. Many software development interviews include DSA-based coding problems.
3. What is a data structure?
A data structure is a method of organizing data so that it can be stored, accessed, updated, and processed efficiently. Arrays, linked lists, stacks, queues, trees, graphs, and hash tables are common examples.
4. What is an algorithm?
An algorithm is a sequence of logical steps used to solve a particular problem. Searching, sorting, graph traversal, and finding the shortest path are examples of algorithmic problems.
5. What is the difference between a data structure and an algorithm?
A data structure determines how data is organized and stored. An algorithm determines how a problem is solved or how the stored data is processed.
6. What is time complexity?
Time complexity describes how the running time of an algorithm changes as the size of the input increases. Big O notation is commonly used to represent time complexity.
7. What is space complexity?
Space complexity describes the amount of additional memory an algorithm requires as the input size increases.
8. What is Big O notation?
Big O notation describes the upper-bound growth rate of an algorithm. Common complexities include O(1), O(log n), O(n), O(n log n), and O(n²).
9. What is O(1) complexity?
O(1) means constant time. The operation takes approximately the same amount of time regardless of the input size. Accessing an element of an array by index is a common example.
10. What is O(n) complexity?
O(n) means linear time. The running time grows approximately in proportion to the input size. Traversing every element of an array once is O(n).
11. What is O(log n) complexity?
O(log n) means logarithmic time. Binary search is a common example because it repeatedly reduces the search space by approximately half.
12. What is O(n²) complexity?
O(n²) means quadratic time. A nested loop where each element is compared with many other elements is a typical example.
13. What is an array?
An array is a collection of elements stored in a structured manner, usually allowing direct access using an index.
14. What is the advantage of an array?
Arrays provide fast indexed access. Accessing an element by its index is generally O(1).
15. What is the disadvantage of an array?
Depending on the implementation, inserting or deleting elements in the middle can require shifting other elements, making those operations potentially O(n).
16. How do you find the largest element in an array?
Traverse the array while maintaining a variable containing the largest value found so far. Each element is compared with that value.
The time complexity is O(n), and the extra space complexity is O(1).
17. How do you find the smallest element in an array?
Initialize a variable with the first element and compare every remaining element against it. Replace the variable whenever a smaller value is found.
18. How do you reverse an array?
Use two pointers. One starts at the beginning and the other at the end. Swap their values and move both pointers toward the center.
19. How do you find duplicate elements in an array?
A hash set can be used to store values already encountered. If an element is already present in the set, it is a duplicate.
20. How do you find the missing number in an array?
If the array contains numbers from 1 to n with one missing value, you can calculate the expected sum and subtract the actual sum. XOR can also be used to solve this problem without overflow concerns.
21. What is a string?
A string is a sequence of characters. Strings are frequently used in interview problems involving searching, comparison, frequency counting, and pattern matching.
22. How do you reverse a string?
You can traverse the string from the last character to the first or use a two-pointer technique if working with a mutable character representation.
23. What is a palindrome?
A palindrome is a sequence that reads the same forward and backward. Examples include “level” and “madam.”
24. How do you check whether a string is a palindrome?
Compare characters from both ends while moving toward the center. If every corresponding pair matches, the string is a palindrome.
25. What is an anagram?
Two strings are anagrams when they contain the same characters with the same frequencies but may appear in a different order. “listen” and “silent” are examples.
26. How can you check whether two strings are anagrams?
You can sort both strings and compare them or count character frequencies using a hash map.
27. What is linear search?
Linear search checks elements sequentially until the required element is found or the collection ends.
Its worst-case time complexity is O(n).
28. What is binary search?
Binary search works on sorted data by repeatedly dividing the search range into two parts.
Its time complexity is O(log n).
29. What condition is required for binary search?
The search space generally needs to be sorted or have a suitable monotonic property.
30. What is sorting?
Sorting means arranging data according to a specified order, such as ascending or descending order.
Array and String Coding Problems
31. How do you find the second-largest element in an array?
Maintain two variables representing the largest and second-largest values while traversing the array. Update them whenever a larger value is encountered.
32. How do you remove duplicates from a sorted array?
Use two pointers. One pointer tracks the position where the next unique value should be placed, while another scans through the array.
33. How do you move all zeroes to the end of an array?
Maintain an index for the next non-zero position. Traverse the array and move non-zero elements toward the front. Fill the remaining positions with zeroes.
34. What is the Two Sum problem?
Given an array and a target value, find two elements whose sum equals the target.
For example, with [2, 7, 11, 15] and target 9, the answer is 2 and 7.
A hash map can solve this efficiently in O(n) average time.
35. What is the three-sum problem?
The three-sum problem asks you to find three values whose sum satisfies a particular target, often zero. A common approach involves sorting and then using two pointers.
36. How do you find the maximum subarray sum?
Kadane’s algorithm can find the maximum contiguous subarray sum in O(n) time.
37. What is Kadane’s algorithm?
Kadane’s algorithm maintains the best subarray sum ending at the current position and the best overall sum encountered so far.
38. How do you merge two sorted arrays?
Use two pointers, one for each array. Compare their current elements and append the smaller value to the result.
39. How do you rotate an array?
Array rotation can be implemented using temporary storage or an in-place reversal technique.
40. How do you find the intersection of two arrays?
You can use a hash set or sort both arrays and use two pointers, depending on the required constraints.
41. How do you find the union of two arrays?
Store elements in a set or use a sorted two-pointer approach when the arrays are sorted.
42. How do you find the frequency of each element?
Use a hash map where each element is used as a key and its occurrence count is stored as the value.
43. How do you find the first non-repeating character?
Count the frequency of each character and then scan the string again to find the first character with frequency one.
44. How do you find the first repeating character?
Maintain a set of characters already encountered. The first character already present in the set is the first repeating character.
45. How do you check whether two strings are rotations of each other?
If two strings have the same length, one common approach is checking whether the second string occurs inside the first string concatenated with itself.
Linked List Interview Questions
46. What is a linked list?
A linked list is a collection of nodes where each node stores data and a reference to another node.
47. What is a singly linked list?
A singly linked list contains nodes where each node points to the next node.
48. What is a doubly linked list?
A doubly linked list contains references to both the previous and next nodes.
49. What is the difference between an array and a linked list?
Arrays generally provide fast indexed access, while linked lists make certain insertions and deletions easier when the relevant node or position is already known.
50. How do you reverse a linked list?
Maintain three references: previous, current, and next. Reverse the current node’s link and move the references forward until the list is completely reversed.
51. How do you find the middle node of a linked list?
Use slow and fast pointers. The slow pointer moves one step while the fast pointer moves two steps.
52. How do you detect a cycle in a linked list?
Floyd’s cycle detection algorithm uses a slow pointer and a fast pointer. If they eventually meet, a cycle exists.
53. How do you find the starting point of a linked-list cycle?
After the slow and fast pointers meet, place one pointer at the head and move both pointers one step at a time. Their meeting point is the cycle’s starting node.
54. How do you merge two sorted linked lists?
Compare the current nodes of both lists and connect the smaller node to the result. Continue until one list is exhausted, then attach the remaining nodes.
55. How do you remove duplicates from a sorted linked list?
Traverse the list and compare each node with the next node. If they contain the same value, skip the duplicate node.
56. How do you find the nth node from the end?
Use two pointers. Move the first pointer n positions ahead, then move both pointers together until the first pointer reaches the end.
57. What is a circular linked list?
A circular linked list is a linked list where the final node points back to the first node.
58. What is the advantage of a doubly linked list?
It allows traversal in both directions and can make certain insertion and deletion operations more convenient.
59. Can a linked list be implemented using arrays?
Yes. A linked-list structure can be simulated using arrays by storing values and indexes representing links between nodes.
60. What is the time complexity of searching an unsorted linked list?
The worst-case time complexity is O(n).
Stack and Queue Interview Questions
61. What is a stack?
A stack is a linear data structure that follows the Last In, First Out principle.
62. What is a queue?
A queue follows the First In, First Out principle.
63. What are common stack operations?
Push adds an element, pop removes the top element, and peek or top returns the top element without removing it.
64. What are common queue operations?
Enqueue adds an element, dequeue removes an element, and front or peek accesses the front element.
65. What is a real-world example of a stack?
A stack of plates is a simple example. The last plate placed on top is generally the first one removed.
66. What is a real-world example of a queue?
People waiting in a line are an example of a queue because the person who arrives first is generally served first.
67. How do you check for balanced parentheses?
Use a stack. Push opening brackets and remove the corresponding opening bracket whenever a valid closing bracket is encountered.
68. How do you implement a stack using queues?
It can be implemented using one or two queues by rearranging elements during push or pop operations.
69. How do you implement a queue using stacks?
Two stacks can be used. One stack handles incoming elements while another provides the required FIFO ordering during removal.
70. What is a priority queue?
A priority queue is a structure where elements are removed according to priority rather than simply according to insertion order.
Hashing Interview Questions
71. What is hashing?
Hashing converts a key into a value or index that can be used for efficient storage and retrieval.
72. What is a hash table?
A hash table stores key-value pairs and generally provides average O(1) lookup, insertion, and deletion.
73. What is a hash collision?
A collision occurs when different keys produce the same hash location.
74. How can hash collisions be handled?
Common techniques include chaining and open addressing.
75. What is a HashMap?
A HashMap is a data structure that stores key-value pairs and provides efficient average-time lookup.
76. What is a HashSet?
A HashSet stores unique elements and is useful when you need fast membership checking.
77. When should you use hashing in an interview problem?
Hashing is useful when you need frequent lookup, duplicate detection, frequency counting, or mapping one value to another.
78. How do you solve Two Sum using hashing?
For every value, calculate the complement required to reach the target. If that complement is already in the hash map, the required pair has been found.
79. How do you find duplicate values using hashing?
Insert every value into a set. If the value already exists, it is a duplicate.
80. How do you count character frequencies?
Create a hash map where each character is a key and increment its count whenever that character appears.
Recursion Interview Questions
81. What is recursion?
Recursion occurs when a function calls itself to solve a smaller version of the same problem.
82. What is a base condition?
The base condition tells a recursive function when to stop calling itself.
83. What happens if recursion has no base case?
The function may continue calling itself until the program runs out of stack memory.
84. What is factorial using recursion?
Factorial follows the relationship n! = n × (n-1)!, with 0! defined as 1.
85. What is recursive Fibonacci?
A recursive Fibonacci function calculates a Fibonacci number using the previous two Fibonacci values.
86. What is tail recursion?
Tail recursion occurs when the recursive call is the final operation performed by the function.
87. What is backtracking?
Backtracking explores possible choices and reverses a choice when it leads to an invalid or unsuccessful path.
88. Where is backtracking used?
Backtracking is commonly used in problems such as permutations, combinations, subsets, N-Queens, and maze-solving.
89. What is the difference between recursion and iteration?
Recursion uses function calls to repeat a process, while iteration uses loops. Recursion can make certain problems easier to express but may use additional call-stack memory.
90. What is memoization?
Memoization stores previously calculated results so that repeated subproblems do not need to be solved again.
Tree Interview Questions
91. What is a tree?
A tree is a hierarchical data structure made up of nodes connected by edges.
92. What is a binary tree?
A binary tree is a tree where each node can have at most two children.
93. What is a binary search tree?
A Binary Search Tree follows an ordering property where values in the left subtree are smaller than the node and values in the right subtree are larger, subject to the chosen duplicate policy.
94. What is the root of a tree?
The root is the topmost node in a tree.
95. What is a leaf node?
A leaf node is a node that has no children.
96. What is tree height?
Tree height is the length of the longest downward path from a node to a leaf, with exact definition depending on whether height is counted in edges or nodes.
97. What is inorder traversal?
Inorder traversal processes the left subtree, the current node, and then the right subtree.
98. What is preorder traversal?
Preorder traversal processes the current node first, followed by the left and right subtrees.
99. What is postorder traversal?
Postorder traversal processes the left subtree, the right subtree, and then the current node.
100. What is level-order traversal?
Level-order traversal processes nodes level by level and is commonly implemented using a queue.
101. Why is inorder traversal important for a BST?
For a standard Binary Search Tree, inorder traversal produces values in sorted order.
102. How do you find the height of a binary tree?
Recursively calculate the height of the left and right subtrees and add one to the larger height.
103. How do you count nodes in a binary tree?
Recursively count nodes in the left and right subtrees and add one for the current node.
104. How do you determine whether two trees are identical?
Compare their corresponding nodes recursively, checking both values and structure.
105. What is a balanced binary tree?
A balanced tree maintains controlled height so that operations can remain efficient. Different balanced-tree definitions may impose different height constraints.
Heap Interview Questions
106. What is a heap?
A heap is a specialized tree-based data structure that satisfies a heap-order property.
107. What is a min-heap?
In a min-heap, the smallest element is at the root.
108. What is a max-heap?
In a max-heap, the largest element is at the root.
109. What is a priority queue?
A priority queue allows elements to be processed according to priority. Heaps are commonly used to implement priority queues.
110. How do you find the kth largest element?
A min-heap of size k can be maintained while traversing the array. At the end, the root represents the kth largest element.
111. What is heapify?
Heapify is the process of restoring the heap property for a particular node or subtree.
112. What is heap sort?
Heap sort builds a heap and repeatedly removes the maximum or minimum element to produce a sorted result.
Its time complexity is O(n log n).
Graph Interview Questions
113. What is a graph?
A graph is a collection of vertices or nodes connected by edges.
114. What is a directed graph?
A directed graph contains edges with a specific direction.
115. What is an undirected graph?
An undirected graph contains edges without a specified direction.
116. What is a weighted graph?
A weighted graph assigns a value or cost to its edges.
117. What is BFS?
Breadth-First Search explores a graph level by level, generally using a queue.
118. What is DFS?
Depth-First Search explores as far as possible along a path before backtracking. It can use recursion or a stack.
119. What is the difference between BFS and DFS?
BFS explores level by level and uses a queue, while DFS explores deeply and commonly uses recursion or a stack.
120. What is a cycle in a graph?
A cycle exists when a path starts and ends at the same vertex without unnecessarily repeating intermediate vertices.
121. How do you detect a cycle in an undirected graph?
DFS with parent tracking or a disjoint-set data structure can be used.
122. How do you detect a cycle in a directed graph?
DFS can track nodes currently in the recursion path. Alternatively, topological-sort-based techniques can be used.
123. What is a connected component?
A connected component is a maximal set of vertices where each vertex is reachable from the others within an undirected graph.
124. What is topological sorting?
Topological sorting produces an ordering of vertices in a directed acyclic graph such that every directed edge goes from an earlier vertex to a later vertex.
125. Where is topological sorting used?
It can be used for dependency ordering, course scheduling, build systems, and task planning.
126. What is Dijkstra’s algorithm?
Dijkstra’s algorithm finds shortest paths from a source vertex to other vertices in graphs with non-negative edge weights.
127. What is a minimum spanning tree?
A minimum spanning tree connects all vertices of a connected weighted undirected graph with minimum possible total edge weight and no cycles.
128. What is Kruskal’s algorithm?
Kruskal’s algorithm constructs a minimum spanning tree by considering edges in increasing order of weight and avoiding cycles.
129. What is Prim’s algorithm?
Prim’s algorithm builds a minimum spanning tree by repeatedly adding the minimum-weight edge that connects the current tree to an unvisited vertex.
130. What is an adjacency matrix?
An adjacency matrix represents graph connections using a two-dimensional matrix.
131. What is an adjacency list?
An adjacency list stores the neighbors of each vertex, usually using a collection associated with each vertex.
Dynamic Programming Interview Questions
132. What is dynamic programming?
Dynamic programming solves problems by breaking them into overlapping subproblems and storing their results to avoid repeated computation.
133. What are the two common approaches to dynamic programming?
The two common approaches are top-down memoization and bottom-up tabulation.
134. What is memoization?
Memoization stores the results of recursive subproblems so they can be reused.
135. What is tabulation?
Tabulation solves subproblems iteratively and stores their results in a table.
136. What is the Fibonacci DP problem?
Instead of calculating the same Fibonacci values repeatedly through recursion, store previously calculated values and reuse them.
137. What is the climbing stairs problem?
The climbing stairs problem asks how many ways a person can reach the top when they can take one or more specified step sizes, commonly one or two.
138. What is the 0/1 Knapsack problem?
It asks you to select items with given weights and values to maximize total value while staying within a weight capacity, where each item can generally be selected at most once.
139. What is the longest common subsequence?
The Longest Common Subsequence problem asks for the longest sequence that appears in two strings while preserving the relative order of its characters.
140. What is the longest increasing subsequence?
It asks for the longest subsequence in which values are strictly increasing.
Advanced DSA Coding Questions
141. How do you find the longest substring without repeating characters?
A sliding-window technique with a set or map can be used. Expand the window while characters are unique and shrink it when a duplicate appears.
142. What is the sliding-window technique?
Sliding window maintains a moving range over an array or string. It is useful when solving contiguous subarray or substring problems.
143. What is the two-pointer technique?
Two pointers use two indexes that move through a data structure according to specific rules. It is commonly used for sorted arrays, strings, and linked lists.
144. What is a monotonic stack?
A monotonic stack maintains elements in increasing or decreasing order and is useful for problems such as next greater element and stock span.
145. What is the next greater element problem?
For each element, find the first element to its right that is greater than it. A monotonic stack can solve this efficiently.
146. What is the stock span problem?
The stock span problem asks how many consecutive previous days have prices less than or equal to the current day’s price.
147. How do you find the kth smallest element?
Possible approaches include sorting, maintaining a heap, or using selection algorithms such as Quickselect.
148. What is Quickselect?
Quickselect is a selection algorithm related to Quicksort that can find the kth smallest or largest element efficiently on average.
149. What is a trie?
A trie is a tree-based data structure designed for storing and searching strings, especially when prefixes are important.
150. Where are tries used?
Tries can be used in autocomplete systems, dictionary searches, spell checking, and prefix-based searches.
151. What is union-find?
Union-Find, also called Disjoint Set Union, is a data structure used to maintain groups of connected elements.
152. Where is Union-Find used?
It is commonly used in connectivity problems and algorithms such as Kruskal’s minimum spanning tree algorithm.
153. What is an AVL tree?
An AVL tree is a self-balancing Binary Search Tree where the height difference between the left and right subtrees of each node is kept within a specified limit.
154. What is a Red-Black Tree?
A Red-Black Tree is a self-balancing binary search tree that uses node coloring rules to maintain approximately logarithmic height.
155. What is the difference between a BST and a heap?
A BST maintains ordering between left and right subtrees, while a heap maintains a parent-child priority relationship. They are designed for different operations.
DSA Interview Questions on Problem-Solving
156. What should you do before coding an interview problem?
First understand the requirements, clarify assumptions, identify constraints, consider edge cases, and explain your planned approach.
157. Should you start with the optimized solution?
Not necessarily. A brute-force solution can provide a useful starting point. After explaining it, you can identify its limitations and develop an optimized approach.
158. Why do interviewers ask for brute-force solutions?
Brute-force solutions demonstrate whether you understand the problem. They also provide a baseline from which optimization can be discussed.
159. How do you optimize a DSA solution?
Look for repeated calculations, unnecessary loops, inefficient data structures, and opportunities to use hashing, sorting, binary search, two pointers, sliding windows, heaps, or dynamic programming.
160. What should you say about time complexity?
Explain how the running time grows with input size and identify the dominant operation or loop structure.
161. What should you say about space complexity?
Explain the additional memory used by data structures, recursion, temporary arrays, maps, sets, or other auxiliary storage.
162. What are edge cases?
Edge cases are unusual or boundary inputs that may cause problems, such as empty arrays, one-element arrays, duplicate values, negative numbers, null inputs, or very large inputs.
163. Why should you test your code after writing it?
Testing helps identify logical errors and demonstrates that you have considered different input conditions.
164. What if you don’t know the answer during an interview?
Don’t immediately give up. Explain what you understand, try a simpler approach, and communicate your reasoning. Interviewers often evaluate the problem-solving process as well as the final solution.
165. Is memorizing DSA solutions a good strategy?
Memorizing solutions alone is not effective. Understanding the underlying patterns makes it easier to solve variations of familiar problems.
166. How many DSA problems should a fresher solve?
There is no fixed number. A practical goal is to solve around 100–200 carefully selected problems while understanding the patterns and complexity behind them.
167. Should experienced developers prepare DSA?
Yes. Experienced developers may encounter DSA questions when applying for product companies, senior engineering positions, or roles with coding assessments.
168. Which DSA topics should freshers prioritize?
Freshers should build strong fundamentals in arrays, strings, hashing, searching, sorting, linked lists, stacks, queues, trees, graphs, recursion, and basic dynamic programming.
169. Which DSA topics are usually considered advanced?
Advanced topics can include complex dynamic programming, graph algorithms, tries, segment trees, advanced tree structures, union-find, and sophisticated optimization techniques.
170. How can I improve my DSA problem-solving skills?
Practice consistently, study common patterns, attempt problems independently, analyze failed approaches, review solutions, and revisit difficult problems after some time.
How My Learn Nest Can Help With DSA Preparation
Learning DSA becomes more effective when you follow a structured path instead of randomly solving coding problems.
My Learn Nest provides career-focused technical learning designed to help students, freshers, and professionals build practical skills.
For learners preparing for software development interviews, DSA can provide a strong foundation for understanding programming logic, algorithms, and efficient problem-solving.
The best approach is to combine conceptual learning with regular coding practice. Start with easy problems, progress toward medium-level questions, and gradually challenge yourself with advanced problems.
You can explore technical courses and learning resources through:
My Learn Nest – Official Website
Final Thoughts
DSA interview preparation is not about learning a list of answers and reproducing them during an interview. The real objective is to understand how problems can be represented, how different data structures can be used, and how algorithms can be optimized.
Freshers should begin with fundamentals such as arrays, strings, searching, sorting, linked lists, stacks, and queues. Once these concepts become comfortable, they can progress to trees, graphs, heaps, recursion, backtracking, and dynamic programming.
Experienced developers should also revisit these fundamentals because interview questions often combine multiple concepts.
The most important habit is consistent practice. Solve a problem, understand why the solution works, analyze its complexity, and then try a variation without looking at the answer.
With the right preparation strategy, DSA can become less intimidating and much more manageable. Whether you are preparing for your first job or planning your next career move, strong DSA fundamentals can help you approach technical interviews with greater confidence.
Start your DSA interview preparation with My Learn Nest and build the problem-solving skills needed for your software development career.


