Almost every fresher technical interview in India has at least one round on data structures and algorithms (DSA). Whether you are sitting for a service-company drive or a product-company coding round, interviewers keep coming back to the same core ideas: arrays, linked lists, stacks, trees, sorting and Big-O. This guide collects 25 DSA interview questions for freshers in 2026, with short, simple answers you can explain confidently in your own words.
Key takeaways
- Most fresher DSA interviews focus on arrays, strings, linked lists, stacks, queues, trees, sorting and searching.
- Interviewers expect you to state the time and space complexity of every solution you give.
- Patterns such as two pointers, sliding window, hashing and BFS/DFS solve a large share of common questions.
- Explaining your approach clearly before coding often matters as much as the final code.
Pick one language — C++, Java or Python — and practise every answer below in it. If you are starting from zero, the CodeMBS DSA for Placement course walks through each topic with placement-style problems.
Arrays and strings
1. What is an array, and what is the time complexity of accessing an element?
An array stores elements of the same type in continuous memory. Because the address of any index can be calculated directly, accessing arr[i] takes O(1) time. Inserting or deleting in the middle takes O(n) because elements must shift.
2. How do you reverse an array in place?
Use two pointers: one at the start and one at the end. Swap the two elements, move the left pointer forward and the right pointer backward, and stop when they meet. This takes O(n) time and O(1) extra space.
int l = 0, r = n - 1;
while (l < r) { int t = a[l]; a[l] = a[r]; a[r] = t; l++; r--; }
3. How do you find the second largest element in an array in one pass?
Keep two variables, first and second. For each element, if it is larger than first, move first into second and update first; otherwise, if it is larger than second and not equal to first, update second. One pass, O(n).
4. What is the two-pointer technique?
It uses two indexes that move through the data, often from both ends or at different speeds. It solves problems such as "find a pair with a given sum in a sorted array" in O(n) instead of the O(n²) brute-force approach.
5. What is the sliding window technique?
You keep a "window" of elements and slide it across the array, adding the new element and removing the old one instead of recalculating everything. Example: maximum sum of any k consecutive elements in O(n).
6. How do you check whether two strings are anagrams?
Count the frequency of each character in both strings (using an array of 26 for lowercase letters, or a hash map) and compare the counts. This is O(n). Sorting both strings and comparing also works, in O(n log n).
Linked lists, stacks and queues
7. Array vs linked list: what is the difference?
An array has fixed size and O(1) random access. A linked list grows dynamically and supports O(1) insertion or deletion when you already have the node, but accessing the k-th element takes O(k) because you must walk from the head.
8. How do you reverse a singly linked list?
Walk through the list with three pointers — prev, curr and next. At each step, save curr.next, point curr.next to prev, then move both pointers forward. At the end, prev is the new head.
9. How do you detect a loop in a linked list?
Use Floyd's cycle-detection algorithm: a slow pointer moves one step and a fast pointer moves two steps. If there is a loop, they will eventually meet; if the fast pointer reaches null, there is no loop. O(n) time, O(1) space.
10. How do you find the middle of a linked list in one pass?
Again use slow and fast pointers. When the fast pointer reaches the end, the slow pointer is at the middle.
11. Stack vs queue?
A stack is LIFO (last in, first out) — think of a pile of plates. A queue is FIFO (first in, first out) — think of a ticket line. Stacks are used for function calls, undo and expression evaluation; queues for scheduling and BFS.
12. How do you check whether brackets in an expression are balanced?
Scan the string. Push every opening bracket onto a stack. For every closing bracket, check that the stack is not empty and its top is the matching opening bracket, then pop. At the end, the stack must be empty.
Trees and graphs
13. What is a binary search tree (BST)?
A binary tree in which every node's left subtree has smaller values and the right subtree has larger values. Search, insert and delete take O(log n) on a balanced tree but can degrade to O(n) if the tree becomes skewed.
14. What are inorder, preorder and postorder traversals?
Inorder: left, root, right (gives sorted order for a BST). Preorder: root, left, right (useful for copying a tree). Postorder: left, right, root (useful for deleting a tree).
15. How do you find the height of a binary tree?
Recursively: height of an empty tree is 0; otherwise it is 1 + max(height of left subtree, height of right subtree). This visits each node once, so it is O(n).
16. BFS vs DFS?
Breadth-first search explores level by level using a queue, and finds the shortest path in an unweighted graph. Depth-first search goes as deep as possible first using recursion or a stack, and is useful for cycle detection, topological sort and connected components.
17. How is a graph stored in memory?
Using an adjacency matrix (a V×V grid, good for dense graphs, O(1) edge lookup) or an adjacency list (each vertex stores its neighbours, memory-efficient for sparse graphs). Most interview solutions use adjacency lists.
Sorting, searching and hashing
18. How does binary search work, and what is its condition?
Binary search works only on sorted data. Compare the target with the middle element; if smaller, search the left half, otherwise the right half. Each step halves the range, so it takes O(log n).
19. Compare quick sort and merge sort.
Both average O(n log n). Merge sort is stable and always O(n log n) but needs O(n) extra space. Quick sort sorts in place and is usually faster in practice, but its worst case is O(n²) with poor pivot choices.
20. Which sorting algorithm is best for an almost-sorted array?
Insertion sort, because it runs in close to O(n) when only a few elements are out of place.
21. What is hashing, and what is a collision?
Hashing maps a key to an index with a hash function, giving average O(1) insert and lookup. A collision happens when two keys map to the same index; it is handled by chaining (a list at each index) or open addressing (probing for the next free slot).
22. How do you solve the "Two Sum" problem efficiently?
Loop through the array and store each number's index in a hash map. For each element x, check whether target - x is already in the map. This finds the pair in one pass, O(n) time.
Complexity, recursion and DP
23. What is Big-O notation?
Big-O describes how an algorithm's running time or memory grows as input size grows, focusing on the worst case. Common orders from fastest to slowest: O(1), O(log n), O(n), O(n log n), O(n²), O(2ⁿ).
24. What is recursion, and what is a base case?
Recursion is when a function calls itself on a smaller version of the problem. The base case is the condition that stops the recursion; without it, the function keeps calling itself until a stack overflow occurs.
25. What is dynamic programming?
DP solves problems with overlapping subproblems by storing results so each one is solved only once — either top-down with memoization or bottom-up with a table. Fibonacci with DP drops from O(2ⁿ) to O(n).
How to prepare DSA for placements in 2026
- Master one language first. Know its arrays, strings, lists, maps and sets well. C++ and Java are popular for coding rounds; Python is fine too, and our Python for Placement course starts from zero.
- Learn patterns, not just problems. Group practice by pattern — two pointers, sliding window, hashing, recursion, BFS/DFS — so new questions feel familiar.
- Always say the complexity. End every answer with "This is O(…) time and O(…) space." It is one of the easiest ways to impress an interviewer.
- Practise under time pressure. Company tests such as TCS NQT combine coding with aptitude, so balance DSA with quant and reasoning on the Placement Preparation hub.
- Explain out loud. Do mock interviews with a friend or mentor. Talking through your logic is a skill that needs practice of its own.
Want a guided plan with live classes and placement-style topic tests? See CodeMBS placement courses.
Related guides
- 25 Python Interview Questions for Freshers (2026) & Answers
- Java Interview Questions for Freshers 2026 & Answers
- SQL Interview Questions for Freshers 2026 & Answers
- Tier-3 College Placement Roadmap 2026: 6-Month IT Job Plan
- DSA Roadmap for Placements
FAQ
How much DSA is enough for service-company placements?
For most service-company roles, comfort with arrays, strings, basic linked lists, stacks, queues, sorting and searching is enough to clear the coding round. Higher-package roles and product companies go deeper into trees, graphs and dynamic programming.
Which language is best for DSA interviews?
Any mainstream language works. C++ is popular for speed and its STL, Java is common in enterprise interviews, and Python is quickest to write. Choose one and stay consistent.
How many problems should I solve before placements?
There is no magic number. Covering each core pattern with several problems, and being able to solve similar new ones on your own, matters more than a large count.
Do non-CS students get DSA questions too?
Yes. BSc, BCA and MCA students applying for software roles face the same coding rounds, so the same preparation applies.
Conclusion
DSA interviews reward clear thinking more than memorised code. Learn these 25 questions, practise writing each solution by hand, and always state the complexity. Combine that with aptitude practice and one or two projects, and you will walk into your 2026–27 placement season far more confident.
📢 Get verified job alerts every day — free
Fresher drives, internships and IT jobs with official apply links only. No fake links, no fees.
More articles

WEF Future of Jobs Report 2027: 28% of India’s Jobs Face Disruption by 2032 — What Students Should Learn Now
WEF Future of Jobs Report 2027 says 28% of India's jobs face disruption by 2032. Here are the skills, roles and steps students should focus…
Read article →
Coursera Global Skills Report 2026: India Ranks 40th on AI-Human Skills — What Students Should Learn Next
Coursera Global Skills Report 2026 ranks India 40th on AI-human skills. What the data means for students and which skills to build next.
Read article →