Problem
Minimum Swaps To Binary Palindrome
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.
Examples
01 · Example 1
s = "101000" return = 1
Swap 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.
More Rubrik problems
public int minSwapsToPalindrome(String s) {
// write your code here
}s"101000"
expected1
sign in to submit