Stage lighting preset toggle
A stage lighting desk drives a strip of channels, numbered from 0, and every channel is off when the house opens. preset_channels[i] lists the channels preset i is wired to, written as channel numbers joined by commas, and an empty entry means that preset is wired to nothing at all. Pressing a preset toggles every channel it is wired to, so a channel wired to two pressed presets ends up back off. The order of the presses does not matter and a preset is pressed at most once. Return the fewest presets the operator must press to leave all channel_count channels on, and -1 when no set of presses does that. With no channels there is nothing to light, so return 0. The desk carries at most 12 presets, no preset lists the same channel twice, and every number listed is a real channel.
fewest_preset_presses(preset_channels: list[str], channel_count: int) → int[["0,1","1,2","2"],3]out2[["0,1","1,2","0,2"],3]out-1[["0,1,2"],3]out1State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
[["0,1","1,2","2"],3]2not run yetsample[["0,1","1,2","0,2"],3]-1not run yetsample[["0,1,2"],3]1not run yetsample