Practice Minimum Number of Swaps to Make the Binary String Alternating
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Given a binary string s, return the minimum number of character swaps to make it alternating, or -1 if it is impossible. The string is called alternating if no two adjacent characters are equal. For example, the strings "010" and "1010" are alternating, while the string "0100" is not. Any two characters may be swapped, even if they are not adjacent.
Source: Minimum Number of Swaps to Make the Binary String Alternating on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
s = "111000"
1
# Example 2
s = "010"
0
# Example 3
s = "1110"
-1
Constraints
Related LeetCode Problems
Practice more problems similar to Minimum Number of Swaps to Make the Binary String Alternating.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.