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]?

  1. A. 4
  2. B. 6
  3. C. 5
  4. 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.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic