DSA interview questions with solutions for freshers
Ten DSA questions students report from campus coding rounds, with the idea in plain words, time and space complexity, and links to practice problems that have tested Python, C++ and Java code.
What comes up most
- Arrays and strings: move and rotate, reverse words, leaders, two-pointers and counting.
- Hashing and greedy: pairs, meetings, fewest jumps, counting with a map.
- Simple dynamic programming and maths: best run of days (Kadane), ways to climb, least common multiples and prime numbers.
- With N up to 105, a loop inside a loop is about 1010 steps, too slow. Aim for O(N) or O(N log N).
10 questions, the idea and where to practise
- Move the empty slots to the end (arrays, two pointers): keep a write marker at the front; copy cars forward, fill the rest with 0. O(N), O(1). Practise on TCS NQT: Move the empty slots to the end.
- Find the second-highest score (arrays, one pass): keep the highest and second-highest distinct scores; skip values equal to the highest. O(N). Practise on TCS NQT: Find the second-highest score.
- Rotate the display board by K (arrays, modular): reduce K to its remainder after division by N; the value at position i moves to (i+K) mod N. O(N). Practise on TCS NQT: Rotate the display board.
- Are two names made of the same letters? (strings, counting): use 26 letter counters, skip spaces and convert the names to lowercase first. O(L). Practise on TCS NQT: Are two names made of the same letters?
- Count the pairs that add up to K (hashing): walk once; for each x add the count of K−x seen before. O(N). Practise on Infosys and Accenture: Count the pairs that add up to K.
- Fit the most meetings into one room (greedy, sorting): sort by end time; take a meeting if it starts at or after the last end. O(N log N). Practise on Infosys and Accenture: Fit the most meetings into one room.
- The best run of days (simple dynamic programming, Kadane): keep the best run that ends today; either extend yesterday’s run or start a new one. O(N). Practise on TCS NQT: The best run of days.
- Longest common subsequence (dynamic programming, strings): compare the two prefixes. If their last letters match, extend the result for the shorter prefixes; otherwise take the better result from dropping one letter. O(N×M). Practise on Infosys and Accenture: Longest common subsequence.
- Longest increasing subsequence (dynamic programming with binary search): keep the smallest ending value for each length and use binary search to find where each new value belongs. O(N log N). Practise on Infosys and Accenture: Longest increasing subsequence.
- Check a password (strings, easy): read the whole line; track whether it contains a digit, an uppercase letter, a lowercase letter or a space, and whether it starts with a digit. O(L). Practise on Infosys and Accenture: Check a password.
More practice with tested code in three languages: TCS NQT, Infosys and Accenture, Wipro, Cognizant GenC and Capgemini.
Practise with Savyly
- Savyly's DSA mode: put a problem on your laptop screen, press one key, and get the idea, commented code, complexity and a dry run. AI coding assistant for LeetCode and DSA.
- Mock coding interviews: Savyly asks one DSA problem at a time, you explain the approach out loud and may type code; it pushes on complexity and edge cases. Type
/practiceand pick coding. How the mock interview works. - 15 free minutes, no card, then ₹199 for an hour, ₹499 for 3 hours, ₹999 for an unlimited week or ₹2,999 for an unlimited month, paid once. Diwali offer until 8 November 2026: ₹99, ₹199, ₹499 and ₹999. Pricing.
Questions
Which DSA topics do campus placements ask most?
Arrays and strings, hashing, two-pointers, greedy and simple dynamic programming. The 10 questions above cover each pattern with the idea and complexity.
Where can I practise DSA questions with solutions?
On the practice pages linked above: each problem has the idea in plain words and tested Python, C++ and Java code. Savyly's DSA mode also explains any problem from your screen.
How should I prepare for DSA coding rounds?
Learn one pattern at a time, write the idea in one line before you code, and test edge cases: one element, all equal, empty, and the largest limits. Time yourself, and aim for O(N) or O(N log N) for N up to 10^5.
Does Savyly help with LeetCode and DSA interviews?
Yes. Put a LeetCode, Codeforces or placement problem on your screen, press one key, and Savyly gives the approach, code and complexity. Use /practice for mock coding interviews with feedback.
- Mass recruiter vs product-based strategy for freshers
- Striver vs Love Babbar DSA sheet: which one for placements
- Tier-3 college placement guide: off-campus, projects and referrals
- Take-home assignment for freshers: what it is, how long and what to submit
- System design for freshers: do companies ask it and what to study