FastPrepMinimum-Cost Red–Blue Ball Swaps
Problems/Minimum-Cost Red–Blue Ball Swaps

Minimum-Cost Red–Blue Ball Swaps

Adobe logoAdobe● HardFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Adobe online assessment for full-time roles. The report gives the two ball colors, the limit on red balls, swaps that cost the distance moved one after another, and the final need for a blue ball at every position that started red. We added a limit of 2,000 balls, wording that treats same-color balls as interchangeable, and the function signature.

A row of balls is given by balls: 1 means red and 0 means blue. At most half the balls are red.

One operation swaps the balls at two positions i and j and costs |i - j|. Complete each swap before starting another.

After all swaps, every position that was red in the initial row must contain a blue ball. There is no requirement for the other positions. Return the minimum total cost. Balls of the same color are interchangeable.

Function

minimumBlueSwapCost(balls: int[]) → long

Examples

Example 1

balls = [1,0,1,0]return = 2

Swap positions 0 and 1, then positions 2 and 3. Each costs 1, so the total is 2. Each of the two original red positions must change color, and each swap costs at least 1.

Example 2

balls = [0,1,1,0]return = 2

Swap positions 1 and 0, then positions 2 and 3. The total cost is 1 + 1 = 2, and both initially red positions become blue.

Constraints

  • 1 <= balls.length <= 2000
  • 0 <= balls[i] <= 1
  • At most half of the balls are red: 2 * sum(balls) <= balls.length.

Source note: Screenshots of public Reddit comments describing the reported Adobe OA task and any included author clarification. The practice version adds the details stated in the source note.

More Adobe Online Assessment questions

  • Base Unit ConversionsOA · Seen Nov 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
  • Top-Funded Villages and ProjectsOA · Seen Aug 2026
  • Count Parent Nodes With a Target SumOA · Seen Aug 2026
  • Largest Binary Number by ConcatenationOA · Seen Aug 2026
  • Count Events by CategoryOA · Seen Aug 2026
  • Graph M-ColoringOA · Seen Aug 2026
  • Hall of Shifting TilesOA · Seen Aug 2026
  • K-th Ancestor Subtree Preorder QueryOA · Seen Aug 2026
  • Maze ReachabilityOA · Seen Aug 2026

Similar questions at other companies

  • At Most K Jumps with Quadratic Transition CostInfosys · OAInfosys interview questions
  • Largest Consistent Visiting GroupAuxoAI · OA
  • Delete K Subsets for Maximum ScoreRubrik · OARubrik interview questions
  • Optimize Discount Selection Under a Point BudgetPalantir · OAPalantir interview questions
  • Maximum Index-Weighted Sum with Disjoint SwapsVisa · OAVisa interview questions
  • Maximum Sum of HeightsVirtu Financial · OAVirtu Financial interview questions
  • Pressure-Isolation Shutdown OrderIntuit · OAIntuit interview questions
  • Get Minimum IncrementIBM · OAIBM interview questions
  • Jump Game with Prime-3 StepsUber · OAUber interview questions
  • Maximum Payout with Context SwitchesPhonePe · OAPhonePe interview questions

Adobe interview experiences

  • Adobe New Grad OA: Unit Conversion and Code Review: 1 Experience
  • 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
  • Adobe ML/Research Intern Interviews: 12 Experiences (Part 4 of 4)
All Adobe interview questionsSee Adobe hiring insights
Saved
class Solution {
    public long minimumBlueSwapCost(int[] balls) {
        // Write your solution here
    }
}
Checking account…