Data Structures & AlgorithmsHardGATE CS · TCS NQT

How many index pairs i < j satisfy a[i] > 2 * a[j] for a = [5, 1, 3, 9, 2, 8, 4]?

  1. A. 5
  2. B. 4
  3. C. 3
  4. D. 6

Correct answer: B. 4

A merge-sort count (or a BIT over compressed values) handles this in O(n log n). The check uses strict inequality with the doubled right element; the non-strict version changes the count.

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

Exams that ask this topic