[LeetCode] Toggle Light Bulbs

3842. Toggle Light Bulbs

You are given an array bulbs of integers between 1 and 100.

There are 100 light bulbs numbered from 1 to 100. All of them are switched off initially.

For each element bulbs[i] in the array bulbs:

  • If the bulbs[i]^th light bulb is currently off, switch it on.
  • Otherwise, switch it off.

Return the list of integers denoting the light bulbs that are on in the end, sorted in ascending order. If no bulb is on, return an empty list.

1
2
3
4
5
6
7
8
9
10
11
class Solution {
public:
vector<int> toggleLightBulbs(vector<int>& t) {
unordered_map<int,int> f;
for(auto& n : t) f[n]++;
vector<int> res;
for(auto& [k,v] : f) if(v % 2 ) res.push_back(k);
sort(begin(res), end(res));
return res;
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2026/09/04/PS/LeetCode/toggle-light-bulbs/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.