You are viewing a single comment's thread. Return to all comments →
The editorial says it is a O(n) solution, using binary search. But the array had to be sorted first, so it started with a O(nlogN) solution. By iterating over the array, and making binary search calls, it would be O(nlogN) by itself.
Using a map, we could get a O(n) solution. But, by using binary search, the space complexity does not increase, at least. It wouldn´t make a difference if the array was already sorted, in this case, because the complexity would not change by sorting it or not.
Since the orger is lost after sorting..how can binary search retrun the actual index.
You can add it to an object with cost/index (struct or class)
Create an array of original indexes and sort them instead of the original values.
then u get to add n space?