Data Structures & AlgorithmsVery hardGATE CS

The sequence a1, ..., a14 is generated by a1 = 1 and a(i+1) = (5*a(i) + 3) mod 17. How many pairs (i, j) with i < j satisfy a(i) > a(j)?

  1. A. 34
  2. B. 38
  3. C. 41
  4. D. 53

Correct answer: B. 38

The sequence is [1, 8, 9, 14, 5, 11, 7, 4, 6, 16, 15, 10, 2, 13], all distinct. Of the 91 pairs, 38 are inversions and 53 are ascending pairs.

More Coding Interview Problems questions

Exams that ask this topic