Data Structures & AlgorithmsHard
What is the largest difference between two CONSECUTIVE values after sorting 3 6 9 1 2 15 in ascending order?
- A. 6
- B. 14
- C. 5
- D. 7
Correct answer: A. 6
Sorting places each consecutive pair next to each other, so the maximum gap is the largest of the n−1 adjacent differences. The overall range or the wrong neighbouring pair gives different values.
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
- Selection sort (ascending) is run on 7 2 9 4 1 6, swapping the minimum of the unsorted part into place in each pass, and skipping the swap…
- Sort 7 8 3 12 5 6 15 4 by the NUMBER OF 1-BITS in binary, ascending; values with the same bit count are ordered by value ascending. Give…
- A queue holds 1 2 3 4 5 6 7 8 from front to back. Interleave it: take the front element of the first half, then the front of the second…
- Starting from an empty stack, perform in order: push 4, push 9, pop, push 2, push 7, pop, pop, push 5. Reading from the bottom to the top…
- Take the values of 4 9 2 7 3 8 5 6 1 10 at the ODD 0-based indices (1, 3, 5, …) in order, forming a new sequence. What is the length of…
- Split 8 3 5 1 9 2 7 4 into consecutive blocks of 4 (positions 0–3 and 4–7). For each block take (max − min), and add these two numbers…