Description
Solutions
Minimum Swaps to Make Palindrome
🔥 FULLTIME

You are given a binary string, s, consisting of characters '0' and '1'. Transform this string into a palindrome by performing some operations. In one operation, swap any two characters, s[i] and s[j]. Determine the minimum number of swaps required to make the string a palindrome. If it is impossible to do so, then return -1.

Note: A palindrome is a string that reads the same backward as forward, for example, strings "0", "111", "010", "10101" are palindromes, but strings "001", "10", "11101" are not.

Example 1:

Input:  s = "0100101"
Output: 1
Explanation:
The following shows the minimum number of steps required. It uses 1-based indexing. Swap characters with indices (4, 5)
Constraints:
    :)
Thumbnail 0
Testcase

Result
Case 1

input:

output: