## McAfee Interview Question for Software Engineer / Developers

Team: Sustainability Engineering
Country: India
Interview Type: Written Test

Comment hidden because of low score. Click to expand.
1
of 1 vote

``````def getFinalAmount(initialAmount, betResults):
finalAmount = initialAmount

# Betting starts at 1 dollar.
previousBet = 1
for result in betResults:
# As required, if we can't cover the last bet, return the balance.
if finalAmount < previousBet:
break

assert result in ('L', 'W')
if result == 'L':
# We lost. Deduct from our balance and double the next bet.
finalAmount -= previousBet
previousBet *= 2
elif result == 'W':
# We won. Add our winnings and reset our bet to 1 dollar.
finalAmount += previousBet
previousBet = 1

return finalAmount

# Tests:
assert getFinalAmount(12, 'WWWWWWWW') == 20
assert getFinalAmount(15, 'LLLWLLLL') == 1``````

Comment hidden because of low score. Click to expand.
0

thanks jay for giving the idea to approach this question

Comment hidden because of low score. Click to expand.
0
of 0 vote

public class BetGame {

static Integer finalAmt;
Integer initaialAmt;
Integer betAmt;
String betResultSequence;

public Integer calculatFinalAmount1(Integer initialAmt, String betResultSequence){
finalAmt = initialAmt;
betAmt=1;

for(int i=0; i < betResultSequence.length(); i++){
if((betResultSequence.charAt(i)) == 'L'){
finalAmt -= betAmt;
betAmt *=2;
}else{
finalAmt += betAmt;
betAmt =1;
}
}

return finalAmt;

}
public static void main(String args[]){

BetGame betGame=new BetGame();

finalAmt = betGame.calculatFinalAmount1(15, "LLLWLLLL");

System.out.println(" The final amount of player is: "+ finalAmt);

}

}

Comment hidden because of low score. Click to expand.
0
of 0 vote

int function(int initamount,char *result)
{
int changesum =0,nextbid =0,lastbid = 0,i=0;

changesum = initamount;
nextbid = 1;
lastbid = 1;
while(result[i] != 0)
{
printf("%d %d %d \n",changesum,nextbid,lastbid);
if(result[i] == 'w')
{
changesum += lastbid;
nextbid = lastbid = 1;
}
else if(result[i] == 'l')
{
changesum -= lastbid;
nextbid = 2 * lastbid;
lastbid = nextbid;
}
i++;
}
printf("%d %d %d",changesum,nextbid,lastbid);
}

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````public static int getResult(int initial_amount, String x){

char seq[] = x.toCharArray();
for(int i=0; i<seq.length; i++){

if(seq[i] == 'W' || seq[i] == 'w'){
final_amount = final_amount+bet_amount;
bet_amount = 1;

}
else if(seq[i] =='L' || seq[i] == 'l'){
final_amount = final_amount-bet_amount;
bet_amount = bet_amount*2;
}
else{
return -1;
}
}
return final_amount;``````

}

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````// c# code
static int getFinalAmount(int initialAmount, string betResults)
{
int totalBets = betResults.Length;
int currentBetAmount = 1;
for (int currentBetNumber = 1; currentBetNumber <= totalBets; currentBetNumber++)
{
if (betResults[currentBetNumber - 1].ToString() == "L")
{
initialAmount -= currentBetAmount;
currentBetAmount *= 2;
}
else
{
initialAmount += currentBetAmount;
currentBetAmount = 1;
}
if (currentBetAmount > initialAmount)
{
return initialAmount;
}
}
return initialAmount;
}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````#include <stdio.h>

int bet(int, char*, int);

int main(void) {
printf ("%d", bet(20, "wllw", 4));
return 0;
}

int bet(int v, char *r, int l){
if (v <= 0 || l == 0){
return v;
}

int b = 1;
int vTemp = v;
int i = 0;
for (i = 0; i < l; i++){
vTemp -= b;
if (vTemp < 0){
return vTemp + b;
}
if ( r[i] == 'W' || r[i] == 'w' ){
vTemp += 2*b;
b = 1;
} else if (r[i] == 'L' || r[i] == 'l'){
b *= 2;
} else if (r[i] == '\0'){
break;
}
}
return vTemp;
}``````

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.