Data Structures & AlgorithmsHardICPC regional · Codeforces Div2 C

Problem: An array of length 7 holds the values 0 to 6 in some order; the position of value k is pos[k]. For the array [2, 0, 3, 6, 1, 5, 4], what is the sum of pos[k] over all values k where pos[k] is greater than k?

  1. A. 5
  2. B. 21
  3. C. 3
  4. D. 11

Correct answer: D. 11

pos = [1, 4, 0, 2, 6, 5, 3]; pos[k] > k for k = 0, 1, 4, giving 1 + 4 + 6 = 11. Summing the values k gives 5, summing every position gives 21, and 3 counts the qualifying values.

More Coding Interview Problems questions

Exams that ask this topic