Minimum number of swaps to make a binary string a palindrome (Rubrik OA)
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.
Full Experience
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.
Interview Questions (1)
Minimum swaps to make binary string a palindrome
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 - Explanation: Swap the characters at positions 2 and 5 to obtain a palindrome.