Data Structures & AlgorithmsHardProduct placement · Amazon/Microsoft
One Lomuto partition (pivot = LAST element; i marks the end of the 'less than pivot' region; when a[j] < pivot, increment i and swap a[i], a[j]; finally swap the pivot into position i + 1) is applied to [41, 11, 12, 45, 3, 33, 58, 25]. What is the resulting array?
- A. [11, 12, 3, 25, 41, 33, 58, 45]
- B. [11, 12, 3, 25, 41, 45, 33, 58]
- C. [3, 11, 12, 25, 33, 41, 45, 58]
- D. [25, 11, 12, 33, 3, 45, 58, 41]
Correct answer: A. [11, 12, 3, 25, 41, 33, 58, 45]
Smaller elements are swapped forward in scan order (so their relative order is kept here, but the larger ones get shuffled). The pivot 25 lands at index 3, its final sorted position: [11, 12, 3, 25, 41, 33, 58, 45].
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- Insertion sort (ascending; shift larger elements right, one key comparison per inner-loop test, the loop stops at the first element ≤ the…
- One Hoare partition with the FIRST element as pivot (i moves right while a[i] < pivot, j moves left while a[j] > pivot, swap while i < j…
- How many inversions (pairs i < j with a[i] > a[j]) does [5, 6, 10, 37, 38, 4, 17, 23] have? (This is also the number of swaps bubble sort…
- Keys 112, 95, 54, 144, 21, 31, 32 are inserted in this order into an empty table of size 11 by double hashing: h1(k) = k mod 11, h2(k) = 7…
- Longest substring that can be turned into one repeated letter with at most k replacements (sliding window, window − maxfreq ≤ k). What is…
- A checker counts how many strings are balanced over (), [] and {}. Version A uses a stack; version B only keeps one counter of open minus…