Problem
Minimum Swaps To Binary Palindrome
Learn this problemProblem statement
Given a binary string s consisting only of '0' and '1', return the minimum number of swaps required to rearrange s into a palindrome.
In one swap, you may swap any two characters in the string; the swapped characters do not need to be adjacent. If it is impossible to make s a palindrome, return -1.
Function
minSwapsToPalindrome(s: String) → intExamples
Example 1
s = "101000"return = 1Swap the '1' at index 2 with the '0' at index 5 to obtain "100001", which is a palindrome.
Constraints
The source post did not specify numeric constraints.