dsa · hard

Rank the Backlog Behind

Tickets carry severities, a list of integers (lower is more severe). For each ticket, count how many tickets strictly after it in the list have a lower severity, and return those counts in the same order.

Arguments

Example

severities = [5,2,6,1]

Ticket 5 (index 0): after it sit 2 and 1, both lower → 2. Ticket 2 (index 1): only 1 after it is lower → 1. Ticket 6 (index 2): 1 is lower → 1. Ticket 1 (index 3): nothing after it → 0. Answer [2,1,1,0].

severities = [-1] → nothing after it → [0].

Constraints

1 <= severities.length <= 10^5 -10^4 <= severities[i] <= 10^4 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.

Examples

Example 1

Input:
[5,2,6,1]

Expected:
[2,1,1,0]

Example 2

Input:
[-1]

Expected:
[0]

Example 3

Input:
[2,0,1]

Expected:
[2,0,0]

Open in the Dojo editor