Light Bulbs Left On After All Engineers Finish
Updated
Problem statement
There are n light bulbs, numbered from 1 to n, and all of them start turned off. There are also n engineers, numbered from 1 to n.
Engineer k toggles every k-th light bulb: bulbs k, 2k, 3k, and so on, up to bulb n. Toggling a bulb turns it on if it is off, and off if it is on. So engineer 1 toggles every bulb, engineer 2 toggles every second bulb, engineer 3 toggles every third bulb, and engineer n toggles only bulb n.
After all n engineers finish, return how many light bulbs remain on.
Function
bulbsLeftOn(n: int) → intExamples
Example 1
n = 100return = 10Bulb 12 is toggled by engineers 1, 2, 3, 4, 6 and 12, six times, so it ends off. Bulb 36 is toggled by engineers 1, 2, 3, 4, 6, 9, 12, 18 and 36, nine times, so it ends on. After all 100 engineers finish, exactly 10 bulbs are on, so the answer is 10.
Example 2
n = 6return = 2Bulb 1 is toggled by engineer 1 only: on. Bulb 2 by engineers 1 and 2: off. Bulb 3 by 1 and 3: off. Bulb 4 by 1, 2 and 4: on. Bulb 5 by 1 and 5: off. Bulb 6 by 1, 2, 3 and 6: off. Bulbs 1 and 4 are on, so the answer is 2.
Example 3
n = 16return = 4Bulb 16 is toggled by engineers 1, 2, 4, 8 and 16, five times, so it ends on. Engineer 16 is the last one to touch it. The bulbs left on are 1, 4, 9 and 16, so the answer is 4.
Constraints
1 <= n <= 10^9
More Akuna Capital Online Assessment questions
- Last Digit of the Ways to Split Traders Between Two OfficesOA · Seen Dec 2026
- Delivery Management SystemOA · Seen Nov 2026
- Count Server ReplacementsOA · Seen Nov 2026
- Match Orders by Price and Arrival TimeOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Maximum Remaining Drone PowerOA · Seen Nov 2026
- Rolling MetricsOA · Seen Oct 2026
- Vowel Substring GameOA · Seen Sep 2026
- Competitive ForagingOA · Seen Sep 2026
- Binary CircuitOA · Seen Sep 2026
- Items SortOA · Seen Sep 2026
Similar questions at other companies
- Counting Cows by Their LegsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Summarize Taxi Drivers and RidesBoston Consulting Group · OABoston Consulting Group interview questions
- Total Cost Against the Lowest Earlier PricePayPal · OAPayPal interview questions
- Count Valid Square PairsAuxoAI · OA
- Server InvestmentRippling · OARippling interview questions
- Basic Item DiscountsPalantir · OAPalantir interview questions
- Identification Number Check DigitAbridge · OAAbridge interview questions
- Count Substrings With Identical CharactersVirtu Financial · OAVirtu Financial interview questions
- Next Pascal Row CoefficientIntuit · OAIntuit interview questions
- Digit-Sum Sequence Join PointOpenAI · OAOpenAI interview questions
Akuna Capital interview experiences
- Akuna Capital Quant Trader and QR Interviews: 5 Experiences
- Akuna Capital JQR CodePair Rounds: 8 Experiences (Part 6 of 6)
- Akuna Capital QR Probability Phones: 14 Experiences (Part 5 of 6)
- Akuna Capital QR-ML Interviews: 11 Experiences (Part 4 of 6)
- Akuna Capital QR Regression Rounds: 11 Experiences (Part 3 of 6)
- Akuna Capital QR Coding Interviews: 17 Experiences (Part 2 of 6)