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

Posted
4 Apr 2026
269 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.

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)

  1. 01

    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.

Know someone preparing? Send it to them:WhatsAppLinkedInX

Interviewed at Rubrik recently?

Write up your rounds while you still remember the questions. It helps the next person more than you would think.

Share your experience
Discussion 0

Questions for the author, or how your own interview compared.

Join the discussion

Sign in with Google to comment or ask the author a question.

No comments yet

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