Bulb Switcher II
Medium · Math, Bit Manipulation, Depth-First Search, Breadth-First Search
There is a room with n bulbs labeled from 1 to n that all are turned on initially, and four buttons on the wall. Each of the four buttons has a different functionality where:
You must make exactly presses button presses in total. For each press, you may pick any of the four buttons to press.
Given the two integers n and presses, return the number of different possible statuses after performing all presses button presses.
Example 1
Input: n = 1, presses = 1 Output: 2
Status can be: - [off] by pressing button 1 - [on] by pressing button 2
Example 2
Input: n = 2, presses = 1 Output: 3
Status can be: - [off, off] by pressing button 1 - [on, off] by pressing button 2 - [off, on] by pressing button 3
Example 3
Input: n = 3, presses = 1 Output: 4
Status can be: - [off, off, off] by pressing button 1 - [off, on, off] by pressing button 2 - [on, off, on] by pressing button 3 - [off, on, on] by pressing button 4
Constraints
- 1 <= n <= 1000
- 0 <= presses <= 1000
Starter code (python)
class Solution(object):
def flipLights(self, n, presses):
"""
:type n: int
:type presses: int
:rtype: int
"""
Related problems
- Add Two Numbers (Medium)
- Reverse Integer (Medium)
- Palindrome Number (Easy)
Previous: Maximum Swap · Next: Longest Continuous Increasing Subsequence · All problems
Zepruv is a technical interview practice platform. Read any problem for free; sign in to run your code, submit and keep your progress.