bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 672. Bulb Switcher II

672. Bulb Switcher II

Leetcode Solutions

Optimized State Reduction Approach

  1. Reduce the number of bulbs n to a maximum of 3, as any larger number will not increase the number of unique states.
  2. Reduce the number of presses presses to a maximum of 3 for the same reason.
  3. If presses is 0, return 1 because there is only one state (all lights on).
  4. If n is 1, return 2 if presses is at least 1 because there are only two states (on or off).
  5. If n is 2, return 3 if presses is 1, or 4 if presses is greater than 1.
  6. If n is 3, return 4 if presses is 1, 7 if presses is 2, or 8 if presses is greater than 2.
  7. Return the calculated number of unique states.
UML Thumbnail

DFS + Memoization Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...