Class Solution
java.lang.Object
g1801_1900.s1888_minimum_number_of_flips_to_make_the_binary_string_alternating.Solution
1888 - Minimum Number of Flips to Make the Binary String Alternating.<p>Medium</p>
<p>You are given a binary string <code>s</code>. You are allowed to perform two types of operations on the string in any sequence:</p>
<ul>
<li><strong>Type-1: Remove</strong> the character at the start of the string <code>s</code> and <strong>append</strong> it to the end of the string.</li>
<li><strong>Type-2: Pick</strong> any character in <code>s</code> and <strong>flip</strong> its value, i.e., if its value is <code>'0'</code> it becomes <code>'1'</code> and vice-versa.</li>
</ul>
<p>Return <em>the <strong>minimum</strong> number of <strong>type-2</strong> operations you need to perform</em> <em>such that</em> <code>s</code> <em>becomes <strong>alternating</strong>.</em></p>
<p>The string is called <strong>alternating</strong> if no two adjacent characters are equal.</p>
<ul>
<li>For example, the strings <code>"010"</code> and <code>"1010"</code> are alternating, while the string <code>"0100"</code> is not.</li>
</ul>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> s = “111000”</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong> Use the first operation two times to make s = “100011”.</p>
<p>Then, use the second operation on the third and sixth elements to make s = “101010”.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> s = “010”</p>
<p><strong>Output:</strong> 0</p>
<p><strong>Explanation:</strong> The string is already alternating.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> s = “1110”</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Explanation:</strong> Use the second operation on the second element to make s = “1010”.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= s.length <= 10<sup>5</sup></code></li>
<li><code>s[i]</code> is either <code>'0'</code> or <code>'1'</code>.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
minFlips
-