Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Minimum Switches for Light Bulbs

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Minimum Switches for Light Bulbs. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Given a binary array bulbs where 0 means off and 1 means on, find the minimum number of switch operations needed to turn all bulbs on. One switch operation at index i flips every bulb from i to the end of the array, changing 0 to 1 and 1 to 0. Return the minimum number of operations as an integer.

Constraints

  • 1 <= bulbs.length <= 10^5
  • bulbs[i] is either 0 or 1
  • A switch at index i flips all bulbs from i to the end

Function Signature

def min_switches(bulbs):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output