Company: Flipkart

Difficulty: medium

Problem Statement

Queue Balancing Challenge A string models a line of people waiting from two rival fan clubs, using the characters 'A', 'B', and 'C'. Exactly one 'B' appears, standing as a neutral figure between the two clubs, since supporters of 'A' and 'C' refuse to stand next to each other. Because of this, 'B' naturally splits the line into two sides. Figure out the smallest number of moves it takes to rebuild the line so every 'A' ends up grouped on one side, every 'C' on the other, and 'B' stays in between them. A single move consists of either: Taking the person from the front of the current line and placing them at the end of the line being rebuilt, or Sending that front person to the back of the current line instead, to be considered again later. Note: Even when the arrangement already satisfies the balance rule, the line must still be rebuilt from scratch, so the move count is never zero. Any unbalanced input is guaranteed to contain at least one 'A', one 'B', and one 'C', with 'B' appearing

More Flipkart OA questionsInterview experiences