#K60772. Count of Smaller Numbers After Self
Count of Smaller Numbers After Self
Count of Smaller Numbers After Self
You are given an integer array nums
of size \(n\). For each element \(nums[i]\), your task is to count the number of elements to its right which are strictly smaller than \(nums[i]\). Formally, you need to compute a list \(\text{counts}\) such that:
[ \text{counts}[i] = |{ j \mid j > i \text{ and } nums[j] < nums[i] }|, ]
Input/Output Format: The input is read from standard input and the output is printed to standard output.
Example:
Input: 4 5 2 6 1</p>Output: 2 1 1 0
inputFormat
The first line contains an integer \(n\) denoting the number of elements in the array. The second line contains \(n\) space-separated integers representing the array nums
.
outputFormat
Output a single line containing \(n\) space-separated integers where the \(i\)-th integer is the number of elements to the right of \(nums[i]\) that are smaller than \(nums[i]\).
## sample4
5 2 6 1
2 1 1 0