DSA Interview Questions for Freshers (2026): What Service Companies Actually Ask

Updated August 2026

Most DSA prep content is written for Google-level interviews — and scares freshers away from topics they barely need. Service-company DSA is a different, much more learnable game: arrays, strings, hashing, complexity basics, and clean code under time pressure.

These are the questions at the level TCS NQT, Infosys, Cognizant and Wipro interviews actually operate. Master these before touching hard LeetCode.

Frequently asked questions

What is time complexity, and why does O(n²) vs O(n log n) matter?

It describes how runtime grows with input size. For n = 1 lakh elements, an O(n²) approach does ~10¹⁰ operations (too slow — seconds to minutes) while O(n log n) does ~1.7×10⁶ (instant). Interviewers ask this to check you can predict whether your code will pass the hidden test cases.

How do you find the largest and second-largest element in one pass?

Track two variables: if current > largest, second = largest and largest = current; else if current > second and current != largest, update second. One O(n) pass, no sorting — sorting for a max is the classic fresher mistake interviewers watch for.

How do you check if a string is a palindrome?

Two pointers: one at the start, one at the end, compare and move inward — O(n) time, O(1) space. Follow-up variants: ignore case/spaces, or check if a string can become a palindrome by removing one character.

What is a hashmap, and when do you reach for one?

A key→value structure with average O(1) insert and lookup. Reach for it whenever the phrase "count occurrences", "check if seen before", or "find pairs that sum to X" appears — it converts O(n²) brute force into O(n).

Two-sum: find a pair of numbers adding to a target.

One pass with a hashmap: for each number x, check if target−x is already in the map; if yes, answer found; if no, store x. O(n) time. Explaining WHY this beats the nested-loop O(n²) version is the actual interview answer.

How do you reverse a linked list?

Three pointers — prev (null), curr (head), next. Loop: save next, point curr.next to prev, advance prev and curr. Practise writing it until you can do it without thinking; it is the most-asked linked-list question in Indian fresher interviews.

What is the difference between a stack and a queue, with one real use each?

Stack is LIFO — used for undo history, function-call management, bracket matching. Queue is FIFO — used for task scheduling, BFS, printer jobs. Expect the follow-up: "implement a queue using two stacks."

Check for balanced brackets in an expression.

Push opening brackets on a stack; on a closing bracket, the stack top must be its matching opener (pop it), else invalid; the stack must be empty at the end. O(n). This is the standard stack question in service-company interviews.

What is binary search and what is its trap?

Repeatedly halve a SORTED range: O(log n). The trap: it only works on sorted data, and the classic bug is mid = (low+high)/2 overflowing in some languages — mention low + (high-low)/2 for bonus points.

Find the first non-repeating character in a string.

Two passes: first count frequencies in a hashmap, then scan the string again and return the first character with count 1. O(n). Asked constantly because it tests hashmap + order-preservation thinking together.

What is recursion, and when would you avoid it?

A function calling itself with a smaller input, needing a base case. Avoid when depth can be huge (stack overflow) or when iteration is simpler — e.g., factorial and Fibonacci are usually better iterative. Know the classic: Fibonacci recursion is O(2ⁿ) without memoization.

Rotate an array right by k positions without extra space.

Reverse the whole array, then reverse the first k elements, then reverse the rest — O(n) time, O(1) space. The three-reversal trick is a favourite in Cognizant and Wipro coding rounds.

Don't just read DSA questions — get asked them

Phiny's AI interviews you on exactly these topics, follows up on weak answers, and tells you what a stronger answer looks like. Text interviews are free and unlimited.

Start a free AI mock interview

How to prepare

Where these questions get asked