Players Scoring Lower — Segment Tree / Fenwick

For each player, tally how many players have a lower score than theirs, returning the counts in the original lobby order.

Segment Tree / Fenwick · Easy

The problem

You get a list of scores, one per player. For every player, count how many other players have a strictly lower score. Return the counts in the same order as the scores.

The story

A game lobby has 1 to 400 players, each with a score from 0 to 9, and several players may share a score. The lobby shows every player how many other players scored strictly lower than they did. Return those counts in the same order as the players.

What to return

Constraints

Example

Input
scores = [8, 1, 2, 2, 3]
Output
[4, 0, 1, 1, 3]

Solve it

More in Segment Tree / Fenwick

All algorithm problems