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]?
- A. 14
- B. 11
- C. 13
- 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
- From the values [4, 9, 1, 12, 7, 3, 10, 6], keep as many as possible so that in the kept set the maximum is at most twice the minimum. How…
- Seven people weigh [3, 5, 3, 4, 2, 6, 1] (kg). A boat carries at most two people and at most 7 kg in total. What is the minimum number of…
- Sorted list [1, 2, 4, 6, 7, 9, 11]. How many index pairs i < j satisfy vals[i] + vals[j] <= 10?
- Four tasks each have (time, value): (3,2), (2,5), (4,4), (5,3). Choose any subset of tasks with total time at most 9 to maximise total…
- In how many ways can a set of 6 distinct people be partitioned into groups so that every group has an even number of people (groups are…
- From the values [3, 5, 6, 7, 10], choose any non-empty subset and XOR its elements together. What is the largest value that can be obtained?