Code Room
CodingEasycod-g1406
Subject Two pointersLevel Entry–Mid~12 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

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].

Implement
sorted_squared_deviations(devs: list[int]) → list[int]
Examples
in[[-4,-1,0,3,10]]out[0,1,9,16,100]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.