Skip to content

Practice Bulb Switcher II

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#672
LeetCode Problem

Bulb Switcher II

Problem Statement

The n bulbs numbered 1 through n begin switched on. Four buttons toggle, respectively: every bulb; only even-numbered bulbs; only odd-numbered bulbs; or bulbs numbered 1, 4, 7, 10 and so on. Make exactly presses button presses, choosing any button each time and allowing repeats. Return the number of distinct final on/off arrangements that can result.

Source: Bulb Switcher II on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 1, presses = 1
Output
2

# Example 2

Input
n = 2, presses = 1
Output
3

# Example 3

Input
n = 3, presses = 1
Output
4

Constraints

1 <= n <= 1000
0 <= presses <= 1000

Related LeetCode Problems

Practice more problems similar to Bulb Switcher II.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.