-
Notifications
You must be signed in to change notification settings - Fork 7
LC: Sort Transformed Array
The Essence:
When a given set of sorted points is mapped with quadratic function, the most-left and/or most-right values will have the largest absolute value:

Therefore, the last values in the sorted array will first come from the last indices, then the first indices, until these indices meet at the middle, where they would yield the value for the first element the ascending-sorted array.
In the case where a parameter of the function is negative, the two pointers at the ends will place values at the beginning of the array.
Details
As outlined above, after applying the function to the array, new value will be placed to the array depending on the two pointers at the boundaries of the set. More detailed information and code can be found here: https://github.com/spiralgo/algorithms/pull/128