Data Structures & AlgorithmsHard
What is the MEDIAN of the combined multiset of the sorted arrays 1 3 8 9 and 2 4 6 7 10? (The combined size is odd, so take the middle value.)
- A. 7
- B. 2
- C. 9
- D. 6
Correct answer: D. 6
Merged order 1, 2, 3, 4, 6, 7, 8, 9, 10 has 9 values, so the median is the 5th smallest: 6. Taking the 6th gives 7, taking the middle of the unsorted concatenation gives 2, and 9 is the merged size, not a value.
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
- Using the sorted arrays 1 3 8 9 and 2 4 6 7 10 together, what is the 7-th smallest value (1-based) of the combined multiset?
- Stably partition 5 2 7 4 1 8 6 3 so that all EVEN values come first and all ODD values come after, keeping the original relative order…
- Values in 4 3 2 7 8 2 3 1 lie in the range 1 to 8 (length 8). Using cyclic sort (place each value v at index v−1 by swaps), which values…
- Find the duplicate in 2 5 9 6 9 3 8 9 7 1 (values 1 to 9, one repeated) with Floyd's method: slow = a[slow] and fast = a[a[fast]], both…
- What is the largest difference between two CONSECUTIVE values after sorting 3 6 9 1 2 15 in ascending order?
- 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…