You are playing a game with a deck of cards, half red and half black. After your friend thoroughly shuffles the cards, you cut the deck. Your friend then begins to turn the cards over one at a time, starting from the top of the deck. If, at any time, there are more red cards showing than black cards, you lose.
If this never occurs by they time all the cards have been turned up, you win.
After losing several times in a row, you get frustrated and decide to cheat. After your friend shuffles the deck, you distract him and then secretly look at the cards, to figure out where you should cut the deck.
"Cutting the deck" means to take a stack of cards off the top of the deck, and place this stack on the bottom.
Given a String deck, representing the cards, return the number of cards you should remove from the top of the deck when you cut.
A 'R' indicates a red card, and a 'B' indicates a black card.
The first character of deck represents the top card, and the last character represents the bottom card.
If there are multiple possibilities, return the smallest number.
|