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?
- A. 5
- B. 21
- C. 3
- 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
- Problem: From the string "3a7b2c" the digits are extracted and summed. What is the sum of the digits?
- Problem: The number of ways to place 3 identical red balls and 2 identical blue balls in a row of 5 positions is what value?
- Problem: The matrix [[1,2],[3,4]] is raised to the power 3 (matrix multiplication, not element-wise). What is the entry in row 0, column 0…
- Problem: Starting from the empty binary string, the value of the string "1011" read in base 2 is computed, then 3 is added. What is the…
- Problem: A list is [5, 9, 2, 7]. How many pairs (i, j) with i < j have a[i] + a[j] greater than 10?
- Problem: For the words ["sleep", "steep", "sheep", "creep"] (all of length five), how many unordered pairs differ in exactly one letter…