Light bulbs Alice has arranged N bulbs in a row. The ON bulbs are represented by a character O and the OFF bulbs are represented by an X. She is having one switch, which can turn on and off only the first bulb from the left. Every time she presses the switch, the state of the first bulb toggles. e b These bulbs are having a special feature, a bulb can switch its state automatically if the bulb in its left gets turned off. Alice presses the switch K times. Task Determine the final state of all bulbs.
def lightBulbs(a, b): final_state = "" for i in range(len(a)): if(i==0): if(b%2==0): final_state = final_state + a[i] else: if(a[i]=='X'): final_state = final_state + 'O' else: final_state = final_state + 'X' else: if(a[i-1]=='X'): final_state = final_state + a[i] else: if(a[i]=='X'): final_state = final_state + 'O' else: final_state = final_state + 'X' return final_state lightBulbs("XXXXOXOXXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOX