Queue-Rank Census - Count of Smaller Numbers After Self

A queue winds through a campus check-in. Each person i has a rank nums[i] (smaller means junior). For every position i from front to back, count how many people strictly behind i have a smaller rank than nums[i]. Return an array answer where answer[i] is that count for position i.

Formally, given nums, produce counts where counts[i] = |{ j : j > i and nums[j] < nums[i] }|.

You must handle negative ranks, duplicates, and empty queues efficiently for large n. An O(n^2) scan is correct but too slow at scale. Coordinate compression with a Fenwick Tree or an index-aware merge sort both achieve O(n log n).

Examples
Input: [5,2,6,1]
Output: [2,1,1,0]
Hints

Queue-Rank Census - Count of Smaller Numbers After Self

A queue winds through a campus check-in. Each person `i` has a rank `nums[i]` (smaller means junior). For every position `i` from front to back, count how many people strictly behind `i` have a smaller rank than `nums[i]`. Return an array `answer` where `answer[i]` is that count for position `i`.