Interview prep

Data Structures & Algorithms Interview Questions

Coding rounds still gate most STEM interviews. Pattern recognition beats memorising individual problems.

Questions and answers

01How do you decide between a hash map and a sorted structure?

Hash maps give O(1) average lookup but no ordering; balanced trees and sorted arrays give O(log n) lookup plus range queries and ordered iteration.

02Explain time complexity of common operations on a dynamic array.

Indexing O(1), append amortised O(1), insert or delete in the middle O(n) because of shifting.

03When do you use BFS instead of DFS?

BFS for shortest path in an unweighted graph and level-order traversal; DFS for path existence, cycle detection, topological sort and lower memory on deep graphs.

04What is dynamic programming and how do you recognise it?

Optimal substructure plus overlapping subproblems. If a recursive solution recomputes the same state, memoise it or build a table bottom-up.

05How do you approach a problem you haven't seen before?

Restate it, work a small example by hand, state a brute force with its complexity, then look for the structure — sorting, hashing, two pointers, sliding window or a graph — that removes the redundant work.

How to answer these well

Interviewers are not grading recall — they are checking whether you've hit the failure mode the question describes. Anchor every answer to something you actually shipped or debugged with Data Structures & Algorithms.

Say the trade-off out loud. "I'd use X here, but it costs Y under Z conditions" scores higher than a clean textbook definition every time.

Roles asking for Data Structures & Algorithms

Related prep