Loading...
Loading...
Loading...
A leaderboard lists scores in the order players finished. A pair of players is out of order when the earlier player has a higher score than the later one. Count all such pairs.
Example 1
Input
2 4 1 3 5
Output
3
Example 2
Input
5 4 3 2 1
Output
10
Try the problem first. Open one hint at a time.
Checking every pair is O(n squared), too slow for 100000 scores.
Count the pairs while merging in merge sort.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor