Skip to the code
cf.
+50 XP

#689 Lower Scores After Each Player

hard

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].

Example 1

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.

Example 2

Input: scores = [-1,-1]
Output: [0,0]

An equal score is not lower.

Constraints

  • 1 <= scores.length <= 10^5
  • -10^4 <= scores[i] <= 10^4
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).