Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

How many index pairs i < j of [1, 2, 5, 7, 10] have absolute difference at least 3?

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

Correct answer: D. 8

Of the 10 pairs, only (1,2), (5,7) are closer than 3, so 8 qualify; 'at least' keeps the pairs with difference exactly 3, (2,5) and (7,10). The strict version drops those and gives 6, checking only adjacent pairs gives 2, and 5 is the array length.

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

Exams that ask this topic