Count of Smaller Numbers After Self
Given an integer array nums, return an integer array counts where counts[i] is the number of smaller elements to the right of nums[i].

30:00

Count of Smaller Numbers After Self
hard
Topics
Companies

Given an integer array nums, return an integer array counts where counts[i] is the number of smaller elements to the right of nums[i].

Example 1:
Input: {"nums":[5,2,6,1]}
Output: [2,1,1,0]
Constraints:
  • 1nums.length1051 \leq \text{nums.length} \leq 10^5

  • 104nums[i]104-10^4 \leq \text{nums}[i] \leq 10^4

Input
arr ={"nums":[5,2,6,1]}

Process from right to left, maintaining sorted suffix

Original Array
5
idx:0
2
idx:1
6
idx:2
1
idx:3
Counts (smaller numbers to the right)
-
-
-
-
Variables
No variables to display
DepthFunction Call
Stack empty
0/5