Data Structures & AlgorithmsHardCodeforces Div 2 C · ICPC regional

Array a = [2, 5, 1, 6, 3, 8, 4]. How many ordered pairs of distinct positions (i, j) satisfy a[j] >= 2 * a[i]?

  1. A. 14
  2. B. 11
  3. C. 13
  4. D. 8

Correct answer: C. 13

Sort the values; for each value the qualifying partners form a suffix, which a pointer that moves as the value grows counts in linear time. The inequality is not strict, so a value equal to exactly twice another is included.

More Coding Interview Problems questions

Exams that ask this topic