Minimum number of swaps to make a binary string a palindrome (Rubrik OA)
- Posted
- 4 Apr 2026
Summary
I received an OA question from Rubrik that asked me to find the minimum number of swaps needed to turn a binary string into a palindrome.
How it went
Hi everyone, I recently got this question in an OA (Rubrik):
Given a binary string s consisting of only '0' and '1', find the minimum number of swaps (swap any two characters, not necessarily adjacent) required to make the string a palindrome. If it is impossible, return -1.
Example: Input: s = "101000" Output: 1
(swap the chars at position '2' & position '5')
Can anyone please share the exact question link for practice if they have it handy?
or best - if you have solution, please post this question to leetcode.
Questions asked (1)
- 01
Minimum swaps to make binary string a palindrome
Data Structures & Algorithms
Given a binary string
sconsisting of only'0'and'1', find the minimum number of swaps (swap any two characters, not necessarily adjacent) required to make the string a palindrome. If it is impossible, return-1.Example:
- Input:
s = "101000" - Output:
1 - Explanation: Swap the characters at positions 2 and 5 to obtain a palindrome.
- Input: