VMware coding Challenge: Coin Toss Betting
1 static int CoinTossEndAmount(int betAmount, String coinTossResults) { 2 if (betAmount <=0 || coinTossResults.length() == 0) return betAmount; 3 long Amount = betAmount; 4 long onebet = 1; 5 for (int i=0; i<coinTossResults.length(); i++) { 6 if (coinTossResults.charAt(i) == 'H') { 7 Amount += onebet; 8 onebet *= 2; 9 } 10 else { 11 Amount -= onebet; 12 onebet /= 2; 13 } 14 if (Amount < onebet) return 0; 15 if (onebet < 1) onebet = 1; 16 } 17 return (int)Amount; 18 }VMware coding Challenge: Coin Toss Betting