DSA interview question
An embedded device must sort sensor readings in place with guaranteed O(n log n) time and O(1) extra memory. Quicksort's worst case and merge sort's buffer are both unacceptable. Heap sort meets all three, and building it exercises every heap fundamental:
2i + 1 and 2i + 2)Example: [5, 2, 9, 1, 5, 6] → [1, 2, 5, 5, 6, 9].
void heapSort(vector<int>& a); // ascending, in place
| Input | Output | Explanation |
|---|---|---|
[5, 2, 9, 1, 5, 6] | [1, 2, 5, 5, 6, 9] | Duplicates are fine |
[3, 2, 1] | [1, 2, 3] | |
[-1, -3, 2, 0] | [-3, -1, 0, 2] | |
[7] | [7] | |
[] | [] |
(Confirm: in-place, O(1) extra memory; stability isn't required, and heap sort isn't stable.)
On Practick another engineer interviews you live for 60 minutes on a question from this bank. They have the full interviewer guide beside the call: the expected answer to every follow-up, hints to give if you stall, and a scoring rubric. You get the model solution once the session settles. It is free: interview someone for an hour and you have earned your own.
Book a free mock interviewAll 474 dsa interview questions
DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in