Interview Prep
Coding & DSA Interview Questions
The concepts behind data-structure and algorithm interview questions — paired with the practice problems that let you actually write the code.
12 of 12 Coding & DSA questions shown. Answers are hidden by default — try each one before revealing it.
1.On average, what is the time complexity of looking up a value by key in a well-implemented hash table?
Easyhash-tablecomplexity
2.You need to implement an LRU (least-recently-used) cache whose get and put operations both run in O(1) time. Which combination of data structures achieves this?
Harddata-structuresdesignlinked-list
3.What is the time complexity of binary search on a sorted array of n elements?
Easysearchingcomplexityarrays
4.What is the worst-case time complexity of quicksort when the pivot is chosen naively, such as always taking the first element?
Hardsortingcomplexity
5.Which data structure would you use to perform a level-order (breadth-first) traversal of a binary tree?
Easytreesbfsqueue
6.You compute the nth Fibonacci number iteratively, keeping only the previous two values in two variables as you loop up to n. What is the auxiliary space complexity?
Mediumrecursioncomplexitydynamic-programming
7.Given an array of integers and a target value, how would you find the two numbers in the array that add up to the target? Walk through your approach and give its time and space complexity.
Easyarrayshash-tablecomplexity
8.Explain how binary search works, and why the input array must be sorted for it to be correct. What happens if you run it on an unsorted array?
Easysearchingarrayscomplexity
9.How would you check whether a given string is a palindrome, ignoring case and any non-alphanumeric characters? Describe your approach and its time and space complexity.
Mediumstringstwo-pointerscomplexity
10.How would you determine whether a string of brackets — for example '{[()]}' — is balanced? Explain your approach and why a stack is the natural structure for it.
Mediumstacksstrings
11.Given a sentence, how would you reverse the order of the words (not the letters within each word) — for example turning 'the sky is blue' into 'blue is sky the'? Discuss at least two approaches and the trade-offs between them.
Mediumstringsarrays
12.Explain what memoization means and why it changes the time complexity of computing the nth Fibonacci number from exponential to linear.
Mediumrecursiondynamic-programmingcomplexity