Betting game
Submissions: 5869   Accuracy:


  Difficulty: Medium   Marks: 4

You are involved in a betting game whose rules are as follows :
a) If you win a round, the bet amount will be added to your current sum and next bet amount will become $1;
b) If you lose a round, the bet amount will be reduced from your current sum and next bet will become twice the previous.
c) game ends either when all the rounds are complete or when you don't have sufficient sum.
Initially, you are given with a string consisiting of characters from the set {'W', 'L'}, where 'W' indicates a win and 'L' indicates a loss, and initial sum is 4. Initial bet amount for the 1st round will be $1.

You need to find and print the amount at the end of the game (final sum) and in case you do not have enough money in between the game to play the next round, then print -1.


The first line of input contains an integer T denoting the number of test cases.
The first line of each test case is a string S made of {W,L}.


Print the amount at the end of the game (final sum) and in case you have not enough money in between the game then print -1.


1 ≤ T ≤ 100
1 ≤ Size of string S ≤ 50




** For More Input/Output Examples Use 'Expected Output' option **

Author: rajatjha

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use, generate link and share the link here.

to report an issue on this page.