Sort Transformed Array
Real-world version: Sorted Dial ResponsesThe 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.
def sorted_responses(offsets: list[int], a: int, b: int, c: int) -> list[int]:public int[] sortedResponses(int[] offsets, int a, int b, int c)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 13 test cases: 13 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Sum of GCD of Formed PairsReal-world version: Total Mesh Cycle of the Gear BinMedium
- Minimum Operations to Transform Array into Alternating PrimeReal-world version: Nudging Readings onto Prime ValuesMedium
- Lexicographically Smallest Negated Permutation that Sums to TargetReal-world version: Turning Numbers Over to Hit a TotalMedium
- Number of Perfect PairsReal-world version: Dial Settings That AgreeMedium