Sorting, Searching and Backtracking Interview Questions for Data Structures and Algorithms
25 Sorting, Searching and Backtracking questions with answers for data structures and algorithms roles — 8 easy, 9 medium, 8 hard.
About Sorting, Searching and Backtracking
Understand merge sort, quicksort, heap sort, counting and radix sort, stability and the n log n lower bound, plus Timsort and quickselect. Master binary search, lower and upper bounds, binary search on the answer and rotated arrays, and learn backtracking with pruning for permutations, subsets and puzzle solvers.
What is a stable sort and why does stability matter?
Show answer
What is backtracking?
Show answer
A bug appeared somewhere in the last 1000 commits. How would you find the commit that introduced it quickly?
Show answer
HR wants an employee list sorted by department, and by salary within each department. How would you do it?
Show answer
Write an iterative binary search that returns the index of a target or -1.
Show answer
Compute the integer square root of a number using binary search.
Show answer
Tell me about yourself for a software engineer role.
Show answer
How does merge sort work and what are its properties?
Show answer
How does quicksort work and why does pivot choice matter?
Show answer
What are lower bound and upper bound, and what common bugs appear in binary search?
Show answer
Packages with given weights must be shipped in order within D days. How do you find the minimum ship capacity?
Show answer
A sorted array has been rotated at an unknown point. How can you still search it in O(log n)?
Show answer
Implement merge sort.
Show answer
Find the first and last position of a target in a sorted array.
Show answer
Generate all permutations of a list of distinct numbers using backtracking.
Show answer
Why are you looking for a change from your current job?
Show answer
Why can comparison sorts not beat O(n log n), and how do counting and radix sort get around it?
Show answer
What does binary search on the answer mean?
Show answer
What is Timsort and why do Python and Java use it?
Show answer
What is quickselect and when is it better than sorting?
Show answer
You must sort a 10 GB file of records on a machine with 1 GB of RAM. How would you do it?
Show answer
A Sudoku solver using plain backtracking is too slow on hard puzzles. How would you speed it up?
Show answer
Search for a target in a rotated sorted array.
Show answer
Tell me about a time you made slow code significantly faster at work.
Show answer
Frequently asked questions
How important is Sorting, Searching and Backtracking in Data Structures and Algorithms interviews?
Understand merge sort, quicksort, heap sort, counting and radix sort, stability and the n log n lower bound, plus Timsort and quickselect. Master binary search, lower and upper bounds, binary search on the answer and rotated arrays, and learn backtracking with pruning for permutations, subsets and puzzle solvers.
How should I use the Sorting, Searching and Backtracking sheet?
Go top to bottom — easy to hard. Answer before opening each answer, tick what you solved and save misses to Last-Minute Revision.