Skip to main content
Back to problems
#3842
Easy Algorithms

Toggle light bulbs

Array Hash Table Sorting Simulation
71.9% acceptance
Mar 15, 2026
57
2
You are given an array bulbs of integers between 1 and 100. There are 100 light bulbs numbered from 1 to 100. All switched off initially. For each element bulbs[i]: toggle the bulb. Return the list of bulbs that are on, sorted ascending.

Solution

Rust
Time O(n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn toggle_light_bulbs(bulbs: Vec<i32>) -> Vec<i32> {
    let mut state = [false; 101];
    for &b in &bulbs {
      state[b as usize] = !state[b as usize];
    }
    (1..=100).filter(|&i| state[i as usize]).collect()
  }
}