Open Lockers After Toggle Passes
Reported by candidates from Tekion's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
This Tekion OA, reported in September 2026, looks like a simulation problem and isn't. Lockers, toggle passes, count the open ones. If you start nesting loops, you're doing too much work. The report even called it a bulb-switcher variation, and that's the tell. With n up to 10^6, brute force is a trap that burns your time. The real answer fits in one line. If you blank on the trick under the clock, StealthCoder is the invisible safety net that surfaces the solution during the live OA.
The problem
There are n lockers in a hallway, numbered 1 through n. Every locker starts closed. You make exactly n passes. On pass i (1 <= i <= n), toggle every locker whose number is a multiple of i: a closed locker opens and an open locker closes. Return how many lockers are open after the final pass. What the interview report shared The report asked how many of 100 initially closed lockers remain open after 100 toggle passes, and called the exercise a bulb-switcher variation. Function openLockers(n: int) → int Examples Example 1 n = 100 return = 10 After 100 passes, a locker stays open only when it is toggled an odd number of times. That happens exactly for the perfect squares 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, so 10 lockers are open. Example 2 n = 3 return = 1 Pass 1 opens lockers 1, 2, 3. Pass 2 closes locker 2. Pass 3 closes locker 3. Only locker 1 remains open. Constraints 1 <= n <= 10^6.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Here's what it reduces to. Locker k gets toggled once for every divisor of k. It ends open only if it has an odd number of divisors. Divisors pair up as (d, k/d), so the count is odd only when d equals k/d, which means k is a perfect square. So the answer is the number of perfect squares from 1 to n, which is floor(sqrt(n)). For n = 100 that's 10. For n = 3 that's 1. The common pitfall is simulating all n passes, which is roughly n log n toggles and wastes effort. The second pitfall is floating point sqrt. Use an integer square root, or compute the float result and then adjust while r*r > n or (r+1)*(r+1) <= n. If you freeze mid-assessment, StealthCoder can hand you the one-liner so you only have to type it and check the edge cases.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Open Lockers After Toggle Passes cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as bulb switcher. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Tekion's OA.
Tekion reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Open Lockers After Toggle Passes FAQ
What's the trick in the Tekion open lockers problem?+
A locker ends open only if it's toggled an odd number of times, which equals its divisor count. Only perfect squares have an odd number of divisors. So the answer is the count of perfect squares up to n, which is floor(sqrt(n)). No simulation needed.
How hard is this OA question really?+
Easy once you see the math, annoying if you don't. The code is one line. The difficulty is recognizing that divisor parity decides everything. If you simulate, it still works for n up to 10^6, but it's slower than it needs to be.
Is brute force acceptable with n up to 10^6?+
Probably passes for correctness, since the harmonic-sum toggling is about n log n operations. But it's the wrong answer to show. Interviewers who call this a bulb-switcher variation expect the sqrt insight. Use brute force only as a quick check on small inputs.
How do I avoid floating point errors with sqrt?+
Use an integer square root such as math.isqrt in Python. If your language lacks one, compute r as the floor of the float sqrt, then adjust: while r*r > n decrement r, and while (r+1)*(r+1) <= n increment r. That handles perfect squares near 10^6 safely.
How do I prepare for this in 48 hours?+
Learn the divisor parity argument and the bulb switcher family. Write the one-liner, test n = 1, 3, 100 and 10^6. Then spend remaining time on other math-flavored patterns like counting and number theory, since OAs often hide a formula behind a simulation story.