## McAfee Interview Report

- 0of 0 votes

AnswersComplete the function getEqualSumSubstring, which takes a single argument. The single argument is a string s, which contains only non-zero digits.

- Shock March 17, 2013 in India for Sustainability Engineering

This function should print the length of longest contiguous substring of s, such that the length of the substring is 2*N digits (maximum length of the string is 49) and the sum of the leftmost N digits is equal to the sum of the rightmost N digits.If there is no such string, your function should print 0.

Sample Test Cases:

Input #00:

123231

Output #00:

6

Explanation:

1 + 2 + 3 = 2 + 3 + 1.

The length of the longest substring = 6 where the sum of 1st half = 2nd half

Input #01:

986561517416921217551395112859219257312

Output #01:

36| Report Duplicate | Flag | PURGE

McAfee Software Engineer / Developer Algorithm - -2of 2 votes

AnswersIn a game, you bet using the following strategy. Whenever you lose a bet, you double the value of the bet for the next round. Whenever you win, the bet for the next round will be one dollar. You start the round by betting one dollar.

- Shock March 17, 2013 in India for Sustainability Engineering

For example, if you start with 20 dollars, and you win the bet in the first round, lose the bet in the next two rounds and then win the bet in the fourth round, you will end up with 20+1-1-2+4 = 22 dollars.

You are expected to complete the function, getFinalAmount, which takes two arguments. The first argument is an integer initialAmount which is the initial money we amount we have when we start the betting. The second argument is a string betResultsThe ith character of outcome will be either 'W' (win) or 'L' (lose), denoting the result of the ith round.

Your function should return the amount of money you will have after all the rounds are played. If at some point you don't have enough money in your account to cover the value of the bet, you must stop and return the sum you have at that point.

Sample Test Cases:

Input #00:

12

WWWWWWWW

Output #00:

20

Explanation:

The initial amount is 12, for every win, you gain 1 dollar.

There are totally 8 consecutive wins and no losses, hence total money gained = 12 + 8 = 20

Input #01:

15

LLLWLLLL

Output #01:

1

Explanation:

The initial amount is 15. As stated in the problem, the amount of bet doubles for every loss.

1st round - Loss: 15-1 = 14

2nd round - Loss: 14-2 = 12 (Bet doubles)

3rd round - Loss: 12-4 = 8

4th round - Win: 8 + 8 = 16

5th round - Loss:16-1 = 15 (Since the previous bet was a win, this bet has a value of 1 dollar)

6th round - Loss: 15-2 = 13

7th round - Loss: 13-4 = 9

8th round - Loss: 9-8 = 1| Report Duplicate | Flag | PURGE

McAfee Software Engineer / Developer Algorithm

**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.

Open Chat in New Window