FastPrepCheapest Flips to Make Two Binary Strings Equal
Problems/Cheapest Flips to Make Two Binary Strings Equal

Cheapest Flips to Make Two Binary Strings Equal

Adobe logoAdobe● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This problem asks for the cheapest way to make one binary string equal to another. Bits can only be flipped two at a time: any two positions for a set price, or two neighbors for 1. An Adobe MTS 2 report from Noida (posted March 2024, ending in selection) names this as a known practice problem. It was the second of two medium-to-hard questions in the first technical round. The candidate and the interviewer spent about ten minutes on approaches before the candidate coded one that passed the interviewer's tests. The report gives only the problem's name, with no rules, limits or examples.

The move rules here are those of the named problem, written in our own words. Our choices: strings of 1 to 2000 characters, a price from 1 to 1000, and new examples.

Our version is about 95% the same as the reported question.

You have two binary strings a and b of the same length n, and a price x. You want to change a until it equals b. To flip a character means to change '0' to '1' or '1' to '0'. Two moves are allowed, as many times as you like and in any order:

  • Pick any two different positions i and j and flip both a[i] and a[j]. This costs x.
  • Pick a position i with i + 1 < n and flip both a[i] and a[i + 1]. This costs 1.

Return the smallest total cost that makes a equal to b, or -1 if it cannot be done.

Function

minFlipCost(a: String, b: String, x: int) → int

Examples

Example 1

a = "0110010"b = "1010001"x = 3return = 2

The strings differ at positions 0, 1, 5 and 6. Flip neighbors 0 and 1 (cost 1) and neighbors 5 and 6 (cost 1): total 2.

Example 2

a = "10000001"b = "00000000"x = 2return = 2

They differ only at positions 0 and 7. Walking the change along with neighbor flips would cost 7, but one flip of the pair (0, 7) costs x = 2.

Example 3

a = "111"b = "000"x = 5return = -1

All three positions differ. Every flip changes two characters, so the number of differences always stays odd and can never reach 0: the answer is -1.

Constraints

  • 1 <= a.length == b.length <= 2000
  • a and b contain only '0' and '1'
  • 1 <= x <= 1000

More Adobe Phone Screen questions

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
  • Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
  • Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
  • Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
  • Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
  • Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
  • Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026

Similar questions at other companies

  • Longest Palindromic SubstringSiemens · PHONE SCREEN
  • Query Words Within K PositionsPalantir · PHONE SCREENPalantir interview questions
  • Edit DistanceDP World · PHONE SCREEN
  • Longest Palindromic SubstringIBM · PHONE SCREENIBM interview questions
  • Word BreakAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Decode WaysThe D.E. Shaw Group · PHONE SCREENThe D.E. Shaw Group interview questions
  • Edit DistanceAstrotalk · PHONE SCREEN
  • Longest Palindromic SubstringeBay · PHONE SCREENeBay interview questions
  • Validate a Palindrome After Limited DeletionsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Count Palindromic SubstringsThe Voleon Group · PHONE SCREEN

Interview reports that mention this question

  • Adobe MTS Interview Questions: 12 Experiences (Part 2 of 6)
  • Adobe Experienced Hire Interviews: 55 Experiences (Part 1 of 6)

Adobe interview experiences

  • Adobe Web, QA, DevOps, ML Roles: 13 Experiences (Part 3 of 3)
  • Adobe SWE Interviews, Level Unknown: 25 Experiences (Part 2 of 3)
  • Adobe Interviews, Level Unknown: 38 Experiences (Part 1 of 3)
  • Adobe New Grad MTS Interview Questions: 7 Experiences
All Adobe interview questionsSee Adobe hiring insights
Saved
class Solution {
    public int minFlipCost(String a, String b, int x) {
        // Write your code here.
    }
}
Checking account…