transform
that applies the quadratic function to a given x
.answer
to store the transformed elements in sorted order.left = 0
and right = nums.length - 1
.a
is less than 0
, iterate while left <= right
:
a. Apply transform
to nums[left]
and nums[right]
.
b. If the transformed value at left
is less, append it to answer
and increment left
.
c. Otherwise, append the transformed value at right
to answer
and decrement right
.a
is greater than or equal to 0
, iterate while left <= right
:
a. Apply transform
to nums[left]
and nums[right]
.
b. If the transformed value at left
is greater, append it to the start of answer
and increment left
.
c. Otherwise, append the transformed value at right
to the start of answer
and decrement right
.answer
array.