Amazon Online Assessment
Anonymous User
260

Given a binary string that contains only '0' and '1', we need to remove all '01' occurences in a string. More formally, at each second, all '01' substrings are changed to '10'. This process repeats until there are no more '01' substrings in the string. All substrings '01' in the string are changed at the same time. Find the number of seconds it takes for the process to stop

Example: s = "001011"

After t = 0 , s = "001011"
After t = 1 , s = "010101"
After t = 2 , s = "101010"
After t = 3 , s = "110100"
After t = 4, s = "111000"

Hence this process takes 4 seconds.

Comments (0)