Skip to content

Practice Bulb Switcher

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

Medium#319
LeetCode Problem

Bulb Switcher

Problem Statement

There are n bulbs that are initially off. You first turn on all the bulbs, then you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it's off or turning off if it's on). For the ith round, you toggle every i bulb. For the nth round, you only toggle the last bulb. Return the number of bulbs that are on after n rounds.

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

Examples

# Example 1

Input
n = 3
Output
1

# Example 2

Input
n = 0
Output
0

# Example 3

Input
n = 1
Output
1

Constraints

0 <= n <= 10^9

Related LeetCode Problems

Practice more problems similar to Bulb Switcher.

Review your practice with PhantomCodeAI

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