315. Count of Smaller Numbers After Self
315. Count of Smaller Numbers After Self
Description
Difficulty: Hard
Related Topics: Array, Binary Search, Divide and Conquer, Binary Indexed Tree, Segment Tree, Merge Sort, Ordered Set
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:
1 | Input: nums = [5,2,6,1] |
Example 2:
1 | Input: nums = [-1] |
Example 3:
1 | Input: nums = [-1,-1] |
Constraints:
- 1 <= nums.length <= 105
- -104 <= nums[i] <= 104
Hints/Notes
- Merge sort
- Compare tmp array with doing the merge
Solution
Language: C++
1 | class Solution { |