Where It Lands
Imagine sorting nums from smallest to largest with a stable sort, so that equal values keep the order they had. Return the index at which the item now at index i would end up.
Nothing has to be sorted for this: an item lands behind every smaller value, and behind the equal values that stand before it.
Example 1
nums [30,10,20]
i 0
returns 2
Sorted, the list is [10, 20, 30], and 30 stands at index 2.
Example 2
nums [5,3,5,1]
i 2
returns 3
Two values, 3 and 1, are smaller than the 5 at index 2, and the other 5 stands before it. It lands at index 3.
Example 3
nums [7]
i 0
returns 0
A single item stays at index 0.
Constraints
1 <= len(nums) <= 30-100 <= nums[i] <= 1000 <= i < len(nums)
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.