Sort and Print Original Indices
EasyP3Coding
Sort nums in non-decreasing order and return, for each position of the sorted array, the original index of the element placed there.
If two elements are equal, the one with the smaller original index comes first.
Example 1
- Input
- nums = [4,1,3,1]
- Output
- [1,3,2,0]
- Why
- Sorted order is 1 (index 1), 1 (index 3), 3 (index 2), 4 (index 0).
Example 2
- Input
- nums = [2,2,2]
- Output
- [0,1,2]
Example 3
- Input
- nums = [5]
- Output
- [0]
Constraints
- 1 <= nums.length <= 10^5
- 0 <= nums[i] <= 10^9
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 9. ⌘Enter runs, ⌘⇧Enter submits.