Loading...
Loading...
Loading...
A sensor sends readings in time order. Count the pairs of readings where an earlier reading is more than twice a later reading. That is, for positions i before j, the reading at i is greater than 2 times the reading at j.
Example 1
Input
1 3 2 3 1
Output
2
Example 2
Input
2 4 3 5 1
Output
3
Try the problem first. Open one hint at a time.
Count the pairs before merging, while both halves are sorted.
For each left value, a pointer in the right half only moves forward.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor