Need Clarity In Question


Not able to understand why expected value for below sample is 2:
A : [ 1, 1, 1, 1, 1, 0, 0 ]
B : 3


Just by switching on 3rd and 5th bulb will light the entire place.
Initially the corridor is entirely dark so let’s denote it by F F F F F F F.
After we switch on the 3rd bulb corridor will be T T T T T F F
and after we switch on the 5th bulb corridor will be T T T T T T T.
So we need just 2 switch for glowing entire corridor.
Hope you’ll get it now. :slight_smile:


Hi Hari,
This is what i understand from the question and sample examples

a) In the input array the 1’s indicate that these bulbs are working fine and 0’s indicate the bulb switches at these positions are not working.

b) However, the faulty bulbs maybe turned on by the power of a neighbouring working bulb. For example,

0 0 1 with B =3

You cannot turn on the bulbs at index 1 and 2 as they have faulty switches. But you can turn on the bulb at index 3 (since it’s switch isn’t faulty) and because B = 3 , the same bulb can distribute it’s power to neighbouring bulbs upto X-B+1 on it’s left and X+B-1 on it’s right making all the bulbs in the corridor light up.

Instead of mentioning faulty bulbs they should have said faulty switches in the problem statement.