FastPrepMinimum Swaps To Binary Palindrome
Problems/Minimum Swaps To Binary Palindrome

Minimum Swaps To Binary Palindrome

Rubrik logoRubrikOA
QuestionFunctionExamplesConstraints

Problem 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) → int

Examples

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

  • No numeric limits are given for this problem.

More Rubrik problems

  • Delete and Freeze GameOA · Seen Nov 2026
  • Delete K Subsets for Maximum ScoreOA · Seen Nov 2026
  • Distribute Elements Into Two Arrays IIOA · Seen Nov 2026
All Rubrik interview questionsSee Rubrik hiring insights
Saved
class Solution {
    public int minSwapsToPalindrome(String s) {
      // write your code here
    }
}
Checking account…