Tap here to switch tabs
Problem
Submissions

Problem: Minimum Swaps to Make the Binary String Alternating

Try to solve the Minimum Swaps to Make the Binary String Alternating problem.

Statement

Given a binary string s, return the minimum number of character swaps required to transform s into an alternating string, or −1-1 if it is impossible to do so.

A string is called alternating if no two adjacent characters are equal. In a single swap, you can choose any two characters in s and swap their positions.

Constraints:

  • 1≤1 \leq s.length ≤1000\leq 1000

  • s[i] is either '0' or '1'.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Swaps to Make the Binary String Alternating

Try to solve the Minimum Swaps to Make the Binary String Alternating problem.

Statement

Given a binary string s, return the minimum number of character swaps required to transform s into an alternating string, or −1-1 if it is impossible to do so.

A string is called alternating if no two adjacent characters are equal. In a single swap, you can choose any two characters in s and swap their positions.

Constraints:

  • 1≤1 \leq s.length ≤1000\leq 1000

  • s[i] is either '0' or '1'.