<p>You are given a binary string <code>s</code>. In one second, <strong>all</strong> occurrences of <code>&quot;01&quot;</code> are <strong>simultaneously</strong> replaced with <code>&quot;10&quot;</code>. This process <strong>repeats</strong> until no occurrences of <code>&quot;01&quot;</code> exist.</p>

<p>Return<em> the number of seconds needed to complete this process.</em></p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;0110101&quot;
<strong>Output:</strong> 4
<strong>Explanation:</strong> 
After one second, s becomes &quot;1011010&quot;.
After another second, s becomes &quot;1101100&quot;.
After the third second, s becomes &quot;1110100&quot;.
After the fourth second, s becomes &quot;1111000&quot;.
No occurrence of &quot;01&quot; exists any longer, and the process needed 4 seconds to complete,
so we return 4.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;11100&quot;
<strong>Output:</strong> 0
<strong>Explanation:</strong>
No occurrence of &quot;01&quot; exists in s, and the processes needed 0 seconds to complete,
so we return 0.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= s.length &lt;= 1000</code></li>
	<li><code>s[i]</code> is either <code>&#39;0&#39;</code> or <code>&#39;1&#39;</code>.</li>
</ul>

<p>&nbsp;</p>
<p><strong>Follow up:</strong></p>

<p>Can you solve this problem in O(n) time complexity?</p>

class Solution:
    def secondsToRemoveOccurrences(self, s: str) -> int:
        binary_string: List[str] = [char for char in s]
        # print(binary_string)
        time_reqd: int = 0
        prev_binary_string: str = str()
        
        while True:
            
            changed_in_curr_sec: bool = False

            index_: int = 0
            while index_ < len(binary_string) - 1:
                current_character: str = binary_string[index_]
                next_character: str = binary_string[index_+1]

                if current_character == '0' and next_character == '1':
                    binary_string[index_], binary_string[index_+1] = binary_string[index_+1], binary_string[index_]
                    changed_in_curr_sec = True
                    index_ += 2
                    continue
                
                index_ += 1
            
            time_reqd += 1
            # print(f'BinaryString -> {binary_string}')
            if prev_binary_string == ''.join(binary_string) or not changed_in_curr_sec:
                break
            prev_binary_string = ''.join(binary_string)

        return time_reqd - 1

1875