Show problems as
Classic problem #360MediumArrayMathTwo PointersSorting

Sort Transformed Array

Real-world version: Sorted Dial Responses
Tracked in this browser only
Read Sort Transformed Array on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

A tuning rig is swept through a list of dial offsets, given in non-decreasing order and possibly containing repeats. At offset x the rig reports the response

a * x * x + b * x + c

Return the responses of all the offsets, arranged in non-decreasing order. The returned list has one entry per offset, so a repeated offset contributes its response more than once. Any of a, b and c may be zero or negative.

Examples

Example 1

Input
offsets = [-1, 0, 1, 2, 3], a = 1, b = -4, c = 3
Output
[-1, 0, 0, 3, 8]

The five responses are 8, 3, 0, -1 and 0 in dial order, and the returned list is those same five numbers arranged from smallest to largest.

Example 2

Input
offsets = [-4, -2, 0, 1], a = 0, b = -3, c = 1
Output
[-2, 1, 7, 13]

With a zero leading coefficient the responses are 13, 7, 1 and -2, so the returned list reverses the dial order.

Example 3

Input
offsets = [-2, -2, 3, 3], a = 1, b = 1, c = -6
Output
[-4, -4, 6, 6]

Offset -2 reports -4 and offset 3 reports 6. Each offset appears twice, so each response appears twice in the answer.

Constraints

  • 1 <= offsets.length <= 200
  • -100 <= offsets[i], a, b, c <= 100
  • offsets is given in non-decreasing order.

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def sorted_responses(offsets: list[int], a: int, b: int, c: int) -> list[int]:
Java
public int[] sortedResponses(int[] offsets, int a, int b, int c)