What are the most asked DSA interview questions for freshers?

Fresher DSA rounds start with arrays, strings, hash maps, two pointers, binary search, and a stack. Explain the pattern, the complexity, and a dry run.

Priyanka 4 November 2026 DSA
DSA interview questions for freshers
Summarize this article in
Quick Answer

Prepare Big O for your own loops, pair sum with a map, two pointers on a sorted array, binary search including the empty array, valid parentheses, and one tree traversal. Dry-run three items before you say you are done.

Key takeaways

  • State the loop, then the Big O. A nested loop is not linear.
  • A hash map buys expected constant lookup and costs linear extra space.
  • Binary search needs a sorted array and a loop that always shrinks.
  • A stack solves nested brackets. A counter of open brackets does not, once types differ.
  • Name the empty input before you code, then dry-run one normal case.

What are the most asked DSA interview questions for freshers?

DSA means data structures and algorithms. Fresher rounds in India, including service-company tests and many product screens, rarely start with an exotic graph proof. They start with arrays, strings, hashing, two pointers, a binary search you can explain, stack and queue behaviour, and Big O you can apply to your own loop. Recursion and a simple tree traversal appear next. If those are solid, a basic graph or dynamic programming question is a stretch goal, not the first week of revision.

The answer they want is the pattern, the complexity, and a dry run on a tiny input. A correct idea with no example fails when the index is off by one. The list below is a preparation guide. It is not a list of company-specific leaked questions, and it is not a promise that every drive uses the same set.

How do you explain Big O without a speech?

Big O describes how the work grows as the input grows, in the worst case we usually care about. A single pass over an array is linear, O(n). A loop inside a loop over the same array is quadratic, O(n²), unless the inner loop shrinks in a way you can prove. A binary search on a sorted array is logarithmic, O(log n). Hash map lookups are usually constant time, O(1), with the warning that collisions and resizing exist. You compare growth. You do not compare two O(n) solutions as if the constant never matters in real code, and you do not ignore the constant in an interview when the simpler loop is obviously cheaper.

Say the complexity after you describe the loops, not before. “I walk the array once, so this is linear, and I use a set so each lookup is expected constant time.” That sentence fits most fresher hashing problems. If you cannot point at the loop that causes the cost, do not guess a letter.

What array and string patterns should you be able to code?

Reverse a string or an array in place with two pointers. Find a pair that sums to a target, first with a hash map in linear time, and then mention the sorted two-pointer version. Slide a window across a string to find the longest substring without a repeating character, and be honest if you still need the window version written in front of you. Kadane’s idea, a running maximum subarray sum, is worth one dry run because the all-negative case is where people reset the sum wrongly. Frequency counts with a map solve anagrams and “first non-repeating character.”

Practise these in one language you type without looking up syntax. Python and Java are both fine. The Python and Java pages cover the language traps that show up while you code, such as mutating a list you meant to copy, or using == on strings in Java. A DSA round is allowed to fail you for a language bug. Fix those before you collect more problems.

When is a hash map the right structure?

Use a hash map when you need to remember what you have seen, in expected constant time. The pair-sum problem stores the value you still need. A frequency map counts characters. A set is enough when you only care about presence, not a count. The cost is memory. If the interviewer asks for constant extra memory, the map may be forbidden and you need a sort or two pointers instead. Say that trade-off before they ask. It shows you did not reach for a map by habit.

Know the average and the worst case in one line. Average lookup is constant. A hostile or unlucky set of keys can degrade a bucket. You will not be asked to implement a hash function in most fresher rounds. You will be asked what key you store. Pick a key that matches the problem. Storing the whole array as a key is usually a sign you have not found the idea.

What is the two-pointer pattern?

Two pointers means two indexes that move through a sorted array or a string according to a rule, instead of a nested loop. On a sorted array, a left index and a right index can find a pair with a given sum: if the sum is too small, move left rightward; if it is too large, move right leftward. On a palindrome check, they move inward while characters match. The pattern is linear after the sort, so the sort may dominate. Say that. Candidates who claim the whole solution is O(n) after they sorted have missed the sort.

Dry-run four numbers. If you skip the dry run, an off-by-one survives. Move the pointers on the board. Stop when they cross. That physical habit is the answer.

Binary search finds a value in a sorted array by repeatedly cutting the range in half. The array must be sorted, or the cut is meaningless. Keep a low and a high index. The mid point is the probe. If the probe is too small, search the right half. If it is too large, search the left half. The classic bug is computing mid in a way that overflows in some languages, and the classic logic bug is updating low or high without excluding mid, so the loop never ends. Write the loop, then run it on an array of four items and on an empty array.

Also know that binary search is a pattern, not only a library function. “First index where the condition becomes true” is the version that shows up in real problems. If you only memorised the equality version, say so and derive the boundary version slowly. A slow correct boundary is better than a fast wrong one.

What is the difference between a stack and a queue?

A stack is last in, first out. You push and pop the same end. Valid parentheses, undo, and depth-first traversal use it. A queue is first in, first out. You add at one end and remove at the other. A printer line and breadth-first traversal use it. In Java you can show this with an ArrayDeque. In Python, a list can be a stack with append and pop, and a deque is the honest queue because popping from the front of a list is linear. Mention that cost if you use Python. It is a frequent small correction, and panels like candidates who know it.

The parentheses question is the one to code cleanly. Walk the string. Push opening brackets. When you see a closer, the stack’s top must be the matching opener, or the string is invalid. An empty stack at the end means success. Dry-run “([])” and “([)]”. The second one is where a careless counter of open brackets fails and a stack succeeds. Say why the counter is not enough when the bracket types must nest correctly.

How much recursion should a fresher show?

Recursion is a function that calls itself on a smaller input and stops at a base case. Factorial and a countdown are only warm-ups. The useful demo is a binary tree: a node, a left child, a right child, and a function that visits the node, then the left subtree, then the right subtree. That is preorder. Inorder and postorder change the visit order. You should be able to draw a tree of five nodes and write the order without hesitation. The base case is a null node. Forgetting it is the bug.

Mention the cost. Recursion uses call-stack space. A skewed tree can become a deep chain. An iterative stack does the same job with a stack you control. You do not need to rewrite every recursive solution iteratively in the fresher round. You need to know the base case and one traversal. Depth-first uses a stack, whether the language hides it in calls or you write it. Breadth-first uses a queue. That pairing is a favourite follow-up.

Which sorting facts are worth memorising?

Comparison sorts such as merge sort and heap sort are O(n log n). Quicksort is usually that fast and can degrade to quadratic if the pivot is always the worst element. Insertion sort is quadratic and fine for tiny arrays. You rarely code a full sort in a fresher interview if the language has one. You do explain which you would call and what extra memory merge sort wants. Know that sorting is a step inside other problems, and its cost is part of the total. A solution that sorts and then scans is O(n log n), not linear.

Stability is the extra credit. A stable sort keeps equal items in their original order. It matters when you sort by one key and then another. If you do not remember which library sort is stable, say you would check rather than guess. Guessing “all sorts are stable” is a known wrong answer.

What is the minimum you should know about trees and graphs?

A tree is a graph with no cycle, and a binary tree limits a node to two children. A binary search tree keeps smaller keys on the left and larger keys on the right, so a lookup can discard half the tree when the tree is balanced. If it is skewed, the lookup becomes a walk down a line. Say balanced versus skewed. You do not need to code an AVL rotation for most fresher drives. You need the search idea and one traversal.

A graph is nodes and edges. It may have cycles, so a traversal must remember visited nodes or it will loop forever. That sentence is the graph answer many freshers miss. Breadth-first search, with a queue and a visited set, finds a shortest path in an unweighted graph. Depth-first search, with a stack or recursion and a visited set, explores a branch fully. If you have never coded this, practise one grid problem where four directions are the edges. If you have not, do not claim graph fluency. Say trees are ready and graphs are the next week. Then make that week real before a product-company screen.

How should a fresher talk about dynamic programming?

Dynamic programming is for problems that repeat the same subproblem. You store the answer for a smaller input and reuse it. Climbing stairs and a small knapsack are enough to see the idea. Many fresher service-company rounds never reach this. Product screens sometimes do. If you are early in preparation, do not fake a DP solution with a nested loop you cannot relate to a subproblem. Say you would solve it with recursion plus a map of already computed answers, and be ready to fill a tiny table if you have practised one. A two-row table you can fill by hand beats a slogan about optimal substructure.

How do you practise so the interview is coding, not recognition?

Pick one language. Solve a small set properly: reverse, pair sum, anagram, binary search, parentheses, one tree traversal, one sliding window. For each, write the idea in a sentence, the complexity, and a dry run. Repeat the same problem two days later from a blank file. A new problem you cannot finish teaches less than a known pattern you can finish cleanly under a timer. Twenty minutes is a fair fresher limit for these patterns. If you need an hour, you do not know the pattern yet.

Service-company tests often mix aptitude with this coding. Product screens stay longer on the code. Either way, talk while you code: the approach, the edge cases of empty input and one element, then the code. Silent typing followed by a wrong index is hard for the interviewer to help. Narrating a wrong first idea and then correcting it is normal. Panels hire people who correct themselves.

Pondicherry students can drill the language in Java or Python training and the spoken round in placement preparation. DSA practice is still a daily blank-file habit. A course cannot do the dry run for you on the day. After the offer, use the CTC guide so the compensation conversation is as precise as the complexity you just stated.

When do you pick an array instead of a linked list?

An array gives you index access in constant time and stores items in a contiguous block, which is kind to the CPU. Inserting in the middle shifts items. A linked list gives you cheap insertion at a node you already hold, and slow access by index because you walk links. Almost every fresher problem that says “list” wants an array or a dynamic array. A linked list is the right classroom tool for a queue implemented by hand, for understanding pointers, and for a problem that says you must insert and delete at an arbitrary node without shifting. Say the default is the array. Say the linked list when the problem is about nodes. Coding a linked list reversal is still worth one afternoon, because panels use it to see whether you can move pointers without losing the rest of the chain. Draw three nodes. Reverse the arrows. Do not lose the head.

The reversal dry run is the whole answer. If you narrate “I use three pointers: previous, current, and next” and you step through two nodes, you will remember it under pressure. If you only remember the word reverse, the third node will fall off the board.

How do you talk about space, not only time?

Time is how the work grows. Space is how the extra memory grows. An in-place reverse uses a handful of variables, so extra space is constant. A hash map of every item uses linear extra space to buy linear time. A recursive tree walk uses stack space proportional to the height. Mention space when you offer the map solution, so the interviewer knows you see the trade. If they demand constant extra space, drop the map and look for two pointers or a sort. Say which constraint you are obeying. Candidates who recite only time complexity sound unfinished once the panel asks “what does the map cost?”

Input space usually does not count as extra space. Say “extra space” so you are not arguing about the array you were given. This is a small wording habit that keeps the answer clean.

Which edge cases should you name before you code?

Empty input. One element. Already sorted, if you are sorting or searching. Duplicates. Negative numbers, if the problem is about sums. A target that does not exist. For strings, the empty string and a string of one character. For trees, a null root. Say two of these out loud before the first line of code. Then your loop has a place to land. Panels are kinder to a candidate who names the empty case than to a candidate who writes a loop that crashes on it and looks surprised. You can even write the empty return first. It makes the rest of the function easier to read.

After the code, dry-run one normal case and one edge. Two traces catch more bugs than a third verbal explanation. If the trace fails, fix the code. Do not explain why the failing trace is “basically correct.”

How to spend the last two hours before a DSA screen

Do not start a new topic. Re-solve reverse, pair sum, valid parentheses, and one binary search from a blank file. Time each at twenty minutes, including a dry run. If one fails, that is the only one you repeat. Skim Big O for the solutions you just wrote, including extra space for the map. Eat, and sleep. A new graph chapter opened at midnight becomes a confused visited-set in the morning. The patterns you can already dry-run are the ones that pass fresher screens.

During the screen, restate the problem in one sentence and name an edge case before coding. Write the function signature. Dry-run a three-element example after the code, not only before. If you are stuck for more than a few minutes, say the brute force and its complexity, then improve one piece. A quadratic solution you finish and test is often worth more than a linear idea you cannot code. Ask whether the array is sorted before you binary-search it. That question is free, and it saves a wrong algorithm.

How to spend the last two hours before a DSA screen

Do not start a new topic. Re-solve reverse, pair sum, valid parentheses, and one binary search from a blank file. Time each at twenty minutes, including a dry run. If one fails, that is the only one you repeat. Skim Big O for the solutions you just wrote, including extra space for the map. Eat, and sleep. A new graph chapter opened at midnight becomes a confused visited-set in the morning. The patterns you can already dry-run are the ones that pass fresher screens.

During the screen, restate the problem in one sentence and name an edge case before coding. Write the function signature. Dry-run a three-element example after the code, not only before. If you are stuck for more than a few minutes, say the brute force and its complexity, then improve one piece. A quadratic solution you finish and test is often worth more than a linear idea you cannot code. Ask whether the array is sorted before you binary-search it. That question is free, and it saves a wrong algorithm.

After the round, write the question you missed and the first index you got wrong. Fix that index the same day on a blank file. A fresher who repairs one off-by-one error learns more than a fresher who bookmarks ten new problems. Take the pattern back to the list on this page and mark it as coded, not as read. The next screen will change the story and keep the pattern. You want the pattern in your hands.

These answers are a preparation guide for students and freshers, including learners at Asmorix in Pondicherry. A company may ask a different follow-up. This page is not a leaked paper and it is not a promise of a result. Say the short answer, show one example, and revise the same day any question you could not code or click.

Frequently Asked Questions

What are the most asked DSA interview questions for freshers?

Big O, array and string patterns, hash maps, two pointers, binary search, stack versus queue, parentheses, one tree traversal, and sorting complexity. Graphs and dynamic programming are a later step for many fresher drives.

How do you explain time complexity?

Say how the work grows with the input. One pass is linear. A loop inside a loop is usually quadratic. Binary search on a sorted array is logarithmic. Point at the loop that causes the cost.

When should a fresher use a hash map?

When you need to remember what you have seen, such as a pair that sums to a target or a character frequency. Mention the extra memory. If the panel wants constant extra space, look at two pointers instead.

What is the difference between a stack and a queue?

A stack is last in, first out. A queue is first in, first out. Parentheses and depth-first search use a stack. Breadth-first search uses a queue.

What edge cases should I mention?

Empty input, one element, duplicates, a missing target, and a null tree root. Say two of them before you write the loop.

Is DSA required for every fresher company?

Coding tests and many product screens require these patterns. Some analyst roles weigh SQL more heavily. Prepare the pattern set anyway if the drive has an online test.

Have a question about batches or fees?

Talk to an Asmorix counsellor in Pondicherry. Compare syllabus, timings, and placement support before you enroll.

Editorial note: Salary figures and hiring trends in this guide are planning ranges drawn from public salary samples and Asmorix counselling in Pondicherry. They are not an offer. City, company, and the skills you can demo all move the number.

Written by

Priyanka

Priyanka writes career and training guides for Asmorix Technologies, covering IT courses, fresher salaries, interview prep, and job-ready skill paths for students in Pondicherry and across India.

Leave a Reply

Your email address will not be published. Required fields are marked