We use cookies for site analytics. Accept to help us understand how the site is used. See our Privacy Policy for details.
A hard divide & conquer problem, graded against 6 test cases (3 of them hidden).
Split the problem, solve the halves, and combine the results.
Reach for it when you see: A problem that halves cleanly, or a required O(log n) / O(n log n) bound.
More Divide & Conquerproblems →Use merge sort on indices rather than values. During the merge step, when an element from the left half is placed, the number of elements already placed from the right half tells you how many smaller elements were to its right. Accumulate these counts in a result array.
The full reference solution in every supported language stays in the editor above - reveal it there once you have had a real attempt.
Read off this problem's own test suite, so these are the cases a submission actually has to survive.
These apply to the pattern as a whole, not just this problem.