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

- jay March 17, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

thanks jay for giving the idea to approach this question

- Gaurav1204 March 17, 2013 | Flag
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);

}

}

- Gaurav1204 March 17, 2013 | Flag Reply
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);
}

- vipul parashar March 18, 2013 | Flag Reply
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;

}

- Anonymous May 15, 2013 | Flag Reply
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;
        }

- Anant Anand Gupta June 29, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>

int bet(int, char*, int);

int main(void) {
	// your code goes here
	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;
}

- Akshay Jain December 27, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

class Solution
{
static int betBalance(String result)
{
int a=result.length();
int bet=1;
int res=4;
for(int i=0;i<a;i++)
{

if(result.charAt(i)=='W')
{
res+=bet;
bet=1;
}
else if(result.charAt(i)=='L')
{
res-=bet;
bet*=2;
if(res<bet)
{
return -1;
}
error in my code
}
return res;
}
}

- Anonymous April 11, 2024 | Flag Reply


Add a Comment
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.

Learn More

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.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More