Given a line of light bulbs, determine which bulbs are on after a sequence of toggle operations that affect many positions at once.
You are given a row of light bulbs, initially all turned off. A series of toggle operations is performed on the bulbs. Each operation changes the state of one or more bulbs from off to on or from on to off.
Your task is to determine the final state of the bulbs after all operations have been applied.
This problem is typically solved by tracking how many times each bulb is toggled and using parity or a difference-style approach instead of simulating every toggle one by one when possible.
Input Format
- The input describes the number of bulbs and a list of toggle operations.
- Each operation specifies which bulb positions are affected.
- Bulbs are indexed consistently in the range $1..n0..n-1$ depending on the statement version.
Output Format
- Return the final state of each bulb after all operations.
- A bulb that is toggled an odd number of times ends up on; otherwise it ends up off.
Constraints
- .
- The number of operations can be large enough that an simulation may be too slow in the intended solution.
- Use the exact bounds from the original platform version if available.
Example 1
Input
n = 5 operations = [[1, 3], [2, 5]]
Output
[1, 0, 0, 1, 1]
Explanation
Starting with 00000:
- Toggle bulbs 1 through 3 -> 11100
- Toggle bulbs 2 through 5 -> 10011 Final state is [1, 0, 0, 1, 1].
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.