Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div 2
How many pairs i < j in [5, 1, 6, 2, 7, 9, 3] satisfy A[i] > 2·A[j]?
- A. 4
- B. 6
- C. 5
- D. 3
Correct answer: C. 5
The pairs are (5,1), (5,2), (6,2), (7,3) and (9,3). This is a merge-sort variant: count across the halves with two pointers, O(n log n), instead of checking all pairs.
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
- What is the minimum number of adjacent swaps needed to sort [3, 1, 2, 5, 4] into ascending order?
- One Lomuto partition pass with the last element as pivot runs on [3, 8, 2, 5, 1, 4, 7, 6]. What is the array after this pass, before any…
- A three-way partition (Dutch national flag) with a low pointer, a mid pointer and a high pointer runs on [2, 0, 2, 1, 1, 0]. What is the…
- What is the smallest positive integer missing from the array [3, 4, −1, 1]?
- What is the worst-case time complexity of finding the minimum in a rotated sorted array that may contain duplicates, using a binary search…
- For binary search over 1000 distinct sorted values with mid = (lo + hi) / 2 and the loop running while lo ≤ hi, what is the largest number…