flipkart | OA 2023 | binary string
Anonymous User
2096

A network transmitter is transmitting a signal from tower A to tower B. The signal which was received by transmitter B contains some distortions. The received signal N is in the form of a binary sequence consisting of 0s and 15 in a random order. The distortion in a signal is a subsequence of 01 of length two where the first character is 0 and the second character is always 1. Before using the signal, the transmitter must clean the signal by removing the distortions. To clean the signal the transmitter uses an iterative process comprising two filters. Each filter removes a single distortion from N. In each iteration, first filter 1 removes the distortion and then filter 2 removes the distortion. To limit the iterations, once both the filters complete their tasks. then that iteration is marked completed and the next iteration begins. If either of the filters are unable to complete their task, then that iteration will be marked as incomplete and the cleaning process ends. The process is designed so that the first filter tries to maximise the number of iterations and the second filter tries to minimise the number of iterations. The process stores the number of completed iterations if both the filters operate optimally.

Write an algorithm for the transmitter to identify the total number of completed iterations.

Input
The input consists of a string - received signal, representing the transmitted signal which was received by tower B (N).

Output
Print an Integer representing the total number of completed Iterations.

Note
received SignalB consists of Os and 1s only.
A subsequence of 01 is of length two where the first character is 0 and the second character is 1.

Example
Input: 0110110
Output:
1
Explanation:
The transmitted signal received by tower B: 0110110
1st Iteration:
Filter 1 removes the subsequence from (1,2) position. Therefore, N becomes: 10110
Filter 2 removes the subsequence from (2,3) position. Therefore, N becomes: 110
Therefore, 1 iteration completed
2nd Iteration:
Since now the updated transmitted signal is: 110, filter 1 cannot remove the subsequence 01. Therefore, the cleaning process ends here.
Therefore, the final output is: 1

Please help me with this one

Comments (7)