Sort squared deviations

Write codeEasy12 min

Your task

A climate-control dashboard stores each hour’s temperature as a signed deviation from the setpoint, sorted ascending (so it may start negative). The alerting logic needs the squared deviations, also in ascending order. Given the sorted deviations, return their squares sorted ascending in O(n) time, no full re-sort. Hint: the largest square must come from one of the two ends. Example: [-4, -1, 0, 3, 10] gives [0, 1, 9, 16, 100].

Examples

sorted_squared_deviations(devs: list[int]) -> list[int]
Example 1
Inputsorted_squared_deviations([-4, -1, 0, 3, 10])
Output[0, 1, 9, 16, 100]