Halloween Sale
Unlock all premium questions for over 30% off
Minimum Adjacent Swaps for Ball Grouping
Medium
Question
A row of colored balls is written as a string balls, one character per ball: 'R' stands for a red ball and 'W' for a white one. A single move exchanges two balls that sit next to each other, and no other kind of move is allowed. Find the fewest moves needed so that every red ball ends up in one unbroken block. If the red balls already form such a block, the answer is 0.
...
Asked at:Microsoft
More Microsoft interview questions
- Valid Clock Time Combinationsmedium
- Office Gift Delivery Schedulerhard
- Recent Search History Systemhard
- Largest Shared BST Valuemedium
- Minimum Coins to Cover All Amountsmedium
- Group Elements by Common Propertiesmedium
- Largest Tree Root IDmedium
- Employee Shift Timeline Intervalsmedium
OfferRetriever
Master technical interviews with real questions from top companies. Build your confidence and career.
LEGAL
© 2026 Purple Business Holdings LLC. All rights reserved. See Terms of Service.