Replace Elements with Indices in Sorted Array
Given an unsorted array of numbers, return an array where each element is replaced with the index it would have in a sorted array. Example: [8,5,4,3,1] -> [4,3,2,1,0]. Follow-up: Is it possible to solve this faster than O(nlogn)?
Asked at:
Amazon
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
All Regions
Late September, 2024
Amazon
Junior
Given an unsorted array of numbers, return an array where each element is replaced with the index it would have in a sorted array. Example: [8,5,4,3,1] -> [4,3,2,1,0]. Follow-up: Is it possible to solve this faster than O(nlogn)?
Hello Interview Premium
Your account is free and you can post anonymously if you choose.