Ctrl K

A Four-Button Lamp Panel

Medium
A row of lamps lamps is numbered 1 to lamps, and all of them start lit. A panel has four buttons, each toggling its own group of lamps: - **A**: every lamp; - **B**: the even-numbered lamps; - **C**: the odd-numbered lamps; - **D**: lamps 1, 4, 7, 10, … (numbers that leave remainder 1 when divided by 3). You make exactly presses presses, picking any button each time (the same button may be pressed again). Return how many different on/off patterns of the row you can end up with.
Example 1
lamps=2, presses=1 → 3

Button A gives [off, off], button B gives [on, off], button C gives [off, on], button D gives [off, on]. That is three distinct states.

Example 2
lamps=1, presses=0 → 1

No button is pressed, the lamp stays on: one state.

Example 3
lamps=3, presses=2 → 7
Constraints
  • 1 ≤ lamps ≤ 1000
  • 0 ≤ presses ≤ 1000
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsExact Volume With Two Buckets MediumColored Block Pyramid MediumLongest Firework Chain MediumAcross the Park Around the Ponds HardKnight Versus Pawns Hard
loading Python…
Input
lamps=2, presses=1
Expected
3

Run checks the first 3 tests in your browser. Submit checks all 93 tests on the server, hidden ones included.