temps[i] is the temperature in room i. Each room's thermostat may be adjusted once (or left alone), shifting that room's temperature by any whole number of degrees from -limit to limit.
The spread is the difference between the warmest and the coldest room. Return the smallest spread you can achieve.temps=[18, 25, 21], limit=2 → 3
Raise the coldest room to 20, lower the warmest to 23 and leave the third at 21: the spread is 23 - 20 = 3. You cannot do better.
temps=[12, 15, 14, 13], limit=2 → 0
Every room can be set to 13 or 14 degrees, so the spread is 0.
temps=[7], limit=0 → 0
With a single room the warmest and the coldest are the same.
temps=[18, 25, 21], limit=2
3
Run checks the first 3 tests in your browser. Submit checks all 124 tests on the server, hidden ones included.