Amazon | Onsite | SDE I
Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2024-09-25Added By Anonymous
Source: Link
Company: Amazon
Role: SDE I
Interview Stage: Onsite
Location: unknown
Year: unknown
Original Post Content:
I have an array of numbers (not necessarily sorted). How do I return an array of the first index of each number if it was a sorted array?
nums = [8,5,4,3,1]
answer = [4,3,2,1,0]
For each number, you replace it with the first index it would have in a sorted array.
nums = [9, 9, 5, 4, 2, 1]
answer = [4, 4, 3, 2, 1, 0]
Is it possible to do this faster than O(nlogn)? Space does not matter.