A tournament page lists players in the order they finished, with their scores in scores. For each player, it shows how many players who finished after them had a strictly lower score.
Write lowerAfter(scores) that returns an array where position i is the number of indexes j > i with scores[j] < scores[i].
Input: scores = [5,2,6,1] Output: [2,1,1,0]
After 5 come 2 and 1, both lower. After 2 only 1 is lower. After 6 only 1.
Input: scores = [-1,-1] Output: [0,0]
An equal score is not lower.
1 <= scores.length <= 5 * 10^5-10^4 <= scores[i] <= 10^4Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #689 Lower Scores After Each Player. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.