Summary
Given a list of integers, return the index each integer would end up at when sorted.
For example, if the list was [0,8,-1,5,8]
, you should return [1,3,0,2,4]
. Note that the two 8
s maintain their order relative to each other (the sort is stable).
Put another way: For each element in the list, return the number of elements in the list that are: Smaller than the chosen element OR (equal to the element AND appears before the chosen element)
Indexes must start with 0 (not 1)EDIT: given the large pushback, I'll allow 1-based indicies.
Test cases:
0 -> 0
23 -> 0
2,3 -> 0,1
3,2 -> 1,0
2,2 -> 0,1
8,10,4,-1,-1,8 -> 3,5,2,0,1,4
0,1,2,3,4,5,6,7 -> 0,1,2,3,4,5,6,7
7,6,5,4,3,2,1,0 -> 7,6,5,4,3,2,1,0
4,4,0,1,1,2,0,1 -> 6,7,0,2,3,5,1,4
1,1,1,1,1,1,1,1 -> 0,1,2,3,4,5,6,7
1,1,1,1,1,1,1,0 -> 1,2,3,4,5,6,7,0
[0 1 ... n-1]
. \$\endgroup\$8,10,4,-1,-1
test case is very deceptive. Try the4,4,0,1,1,2,0,1
one first. \$\endgroup\$