MediumPro challengePython

Command

PythonDesign PatternsBehavioral

Command turns an action into an object with execute()/undo(), so
callers (like a remote control) can queue, log or reverse actions without
knowing what they do.

Implement LightOnCommand and LightOffCommand (each wraps a Light).
Implement RemoteControl.press(command) (executes and records the command)
and RemoteControl.press_undo() (pops the last command and undoes it).

solve(operations) drives 'on' / 'off' / 'undo' ops through the
remote and returns the light's on state after each op.

Sample tests

Test #1Turn on
Input: [["on"]]
Output: [true]
Test #2Turn on then off
Input: [["on","off"]]
Output: [true,false]
Test #3Undo reverses the last command
Input: [["on","undo"]]
Output: [true,false]
Test #4Undo with empty history is a no-op
Input: [["undo"]]
Output: [false]