State of Eight Server Rack Switches After a Billion Ticks
Last updated: November 29, 2026
Quick Overview
Eight rack switches in a row are each on or off. Every tick, a switch turns on if its two neighbors were both on or both off, otherwise off; the two end switches have one neighbor and always turn off after the first tick. Return the states after n ticks, with n up to 10^9.
Meta
November 29, 20260
0
0 solved
Eight rack switches in a row are each on or off. Every tick, a switch turns on if its two neighbors were both on or both off, otherwise off; the two end switches have one neighbor and always turn off after the first tick. Return the states after n ticks, with n up to 10^9.
A Meta onsite simulation question where direct simulation is too slow, but the state space is tiny. The interviewer looks for cycle detection with a hash map of seen states and correct modular arithmetic on the remaining ticks.
What the Interviewer Expects
- Simulate one tick correctly, including the ends
- Note there are at most 2^8 states, so the sequence must cycle
- Record the first tick each state appears
- Skip ahead using the cycle length
- Optionally encode states as bitmasks for speed
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Prove an upper bound on the cycle length here.
- What if there are 100 switches?
- Compute the state with a bitwise formula in one step.
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: list cells of 8 values in {0, 1} and n in 1..10^9. Rule for each tick: new[i] = 1 if old[i-1] == old[i+1] (for 1 <= i <= 6), and new[0] = new[7] = 0. Output: list of 8 values after n ticks....
High-Level Design
With 8 cells there are at most 256 states (in fact only 64 after the first tick, since the ends are 0), so by the pigeonhole principle the sequence revisits a state within 64 ticks of the start. Once ...