Count Bulbs Left On after Divisor-Indexed Toggles

Quick Overview

Count Bulbs Left On after Divisor-Indexed Toggles. Bulbs 1 through n start off. On round i toggle every bulb whose index is a multiple of i, for rounds 1 through n. Return how many are on at the end.

Count Bulbs Left On after Divisor-Indexed Toggles

Company: LinkedIn

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem Bulbs 1 through n start off. On round i toggle every bulb whose index is a multiple of i, for rounds 1 through n. Return how many are on at the end. ```cpp int bulbSwitch(int n); ``` ### Examples ```text n = 10 -> 3 n = 0 -> 0 ``` ### Constraints - 0 <= n <= 1000000000.

Overview: Count Bulbs Left On after Divisor-Indexed Toggles. Bulbs 1 through n start off. On round i toggle every bulb whose index is a multiple of i, for rounds 1 through n. Return how many are on at the end.

LinkedIn logo
LinkedIn
Source window: 0–3 months · as of Oct 21, 2026
mediumSoftware EngineerOtherCoding & Algorithms
1
0

Problem

Bulbs 1 through n start off. On round i toggle every bulb whose index is a multiple of i, for rounds 1 through n. Return how many are on at the end.

int bulbSwitch(int n);

Examples

n = 10 -> 3
n = 0 -> 0

Constraints

  • 0 <= n <= 1000000000.