FunctionRacerProblemsRace

Panel of Light Switches

BeginnerClassesPython, JavaScript, TypeScript, Java, C++

Implement a class LightPanel for a row of n lights numbered 0 to n - 1. Every light starts off. Write these methods:

i is always between 0 and n - 1. The tests call the methods in sequence and compare every return value. The expected list holds null for the constructor.

Example 1

LightPanel(3)
toggle(0) returns true
toggle(2) returns true
toggle(0) returns false
is_on(2) returns true
count_on() returns 1
all_off() returns 1
is_on(2) returns false
count_on() returns 0

Light 0 is switched on and then off again, so only light 2 is on when count_on runs. all_off reports that one light was on and switches it off.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Classes problems