There are two conditions that are mentioned in the problem: You can think of it in this way, since the 0s must not be consecutive, there must be at least a single 1 in between every 0, ie., the valid solution will be of this form: 0 _ 0 _ 0 _ 0....._0 where the "_" represents a gap, that must be filled by 1s and there cannot be more than two 1s in any gap. If there 'n' 0s, then there will be n1 gaps in between them, and two more gaps at the beginning and the end, so you should have at least n1 1s (to fill the gaps in between) and at most ((n1)*2 + 4) 1s (two 1s in every gap in between and two 1s in the beginning and the end). if you see the last test case, it has one 0 and five 1s. You need to put these five 1s on either side of the single 0 such that no side has more than two 1s, another way to look at this is to take a string with five 1s say "11111", try to put a 0 in this string at any position, you will see that no matter where you put the 0, there will be atleast three consecutive 1s in the resulting string. answered 27 May '17, 11:37
