Minimum number of swaps to make a binary string a palindrome (Rubrik OA)

rubrik logo
rubrik
April 4, 2026 · 1 reads

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)

1.

Minimum swaps to make binary string a palindrome

Data Structures & Algorithms

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.

📣 Found this helpful? Please share it with friends who are preparing for interviews!

Discussion (0)

Share your thoughts and ask questions

Join the Discussion

Sign in with Google to share your thoughts and ask questions

No comments yet

Be the first to share your thoughts and start the discussion!