Example output is a placeholder. Please ignore it.
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.
Examples
01 · Example 1
s = "0100101" return = 1
Output is just a placeholder. Lets ignore it for now..
More Amazon problems
- Count Promotional PeriodsOA · Seen Jun 2026
- Find Maximum Total Amount (SDE I, Fungible :)Seen Jun 2026
- Get Minimum AmountOA · Seen Jun 2026
- Find Minimum CostOA · Seen Jun 2026
- Get Smallest Base SegmentOA · Seen Jun 2026
- Select Least Resource TasksOA · Seen Jun 2026
- Product Category Group SizesPHONE SCREEN · Seen May 2026
- Count Connected ComponentsPHONE SCREEN · Seen May 2026
public int minSwapsToMakePalindrome(String s) {
// write your code here
}
s"0100101"
expected1
sign in to submit