Two Thresholds Stop the Flicker

Easy data structure and algorithm practice puzzle.

A thermostat with one threshold would click on and off many times a minute as the temperature hovered around it, and wear out the heater. Real ones use two. The heater turns on when the temperature drops below low, turns off when it rises above high, and in between it keeps doing whatever it was doing. That gap is called hysteresis. The heater starts off. Given the temperature readings in order, return the heater's state after each one, as 1 for on and 0 for off.

Solve it three ways: snap the jigsaw pieces together, fill in the blanks, or type it from scratch against the tests. This one is free to play, with no account.

Every line of the solution comes with a note explaining why it is there, and a step by step replay shows the code running. At level 3, where you type it yourself, you can ask for an AI mock interview on this problem that ends with a hiring manager's scorecard.

Then grow it into a real project with the Software Engineer button: this puzzle becomes the Event Streak Finder, a pipeline you can run and download. See every Software Engineer project.

More Engineering puzzles

All 22 Engineering practice problems

Browse all 676 puzzles