Description
Solutions
Submission
Maximize Solar Powered Bulbs 🍐

Solar power consumption has increased due to concern over global warming. Some Amazon offices have decided to replace some of their electricity-powered bulbs with solar-powered bulbs. Here electricity-powered means using a wired supply of electricity and solar-powered means powered by an independent solar panel.

In one such office, the lights are arranged sequentially represented by a binary sequence, bulbs. The electricity-powered bulbs are represented by '0', and the solar powered bulbs are '1'.

It is desired to have as many solar-powered bulbs as possible, but the electricity-powered ones are brighter than the solar powered bulbs. An electricity-powered bulb can be replaced by a solar-powered bulb only if the new solar-powered bulb is not adjacent to a solar-powered bulb. More formally, a 0 can be replaced by a 1 if and only if it does not become adjacent to some other 1 on replacement.

Find the maximum number of solar powered bulbs that can be placed in the office. Note that the initial lighting may already have some adjacent solar powered bulbs. The constraint is only for new bulbs.

Note: Report the total number of solar powered bulbs and not just the number of replaced bulbs.

Function Description

Complete the function maximizeSolarPoweredBulbs in the editor.

maximizeSolarPoweredBulbs has the following parameter:

  1. String bulbs: a string representing the arrangement of bulbs

Returns

int: the maximum number of solar powered bulbs that can be placed

Example 1:

Input:  bulbs = "1111110001"
Output: 8
Explanation:
Replacing bulb 8 with solar powered bulb Initially, there are 7 solar powered bulbs. Only the 8th bulb can be replaced with solar. Either of the other two positions is next to a solar powered bulb which violates the rule. With the replacement of 1 bulb, the maximum of 8 solar powered bulbs is achieved. Return -3; (I am questioning this...)
Constraints:
    An unknown myth for now
Thumbnail 0
Testcase

Result
Case 1

input:

output: