315 Count of Smaller Numbers After Self
You are given an integer array nums and you have to return a new counts array. The counts array has the property where counts[i] is the number of smaller elements to the right of nums[i].
Example:
Naive Implementation
The Idea: First I built an array the returns the index for the next smallest element in the array. Then iterating from the end, iterate to count the number of smallest elements beginning from the next smallest element.
Complexity: O(n + n^2) time and O(n) space
Last updated
Was this helpful?