Microsoft Interview Question for Developer Program Engineers


Country: United States
Interview Type: In-Person




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

I got one approach for this,not sure if it is optimum.But with this algorithm in worst case also player will have more money at the end of the game what was with him at the begining.

1- Determine LossCount=n and WinCount=n
2- Determine the money to be bet.
a- If LossCount =0 then bet the whole money
b - Else devide the remaining money by (LossCount + 1)
3- Play the card.
a- If it is loss then LossCount-- and RemaningMoney = RemainingMoney - BetMoney.
b - Else WinCount-- and RemainingMoney=RemainingMoney+BetMoney
4- Go to Step 2 and repeat this till nth time.

Logic for choosig the divider as (LossCount +1) - We need to survive in the game till we start wining.Suppose we have X money and n win and n Loss chnaces.In worst case for the first nth time we lose.So for the next (n+1)th time we need minimum money to play.

- ravi July 08, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Total amount is X
Total loosing moves are N
To survive these N loosing moves and still have some cash left, the amount we can bet on a move is X/(N+1)

Therefore at each stage of the game we bet X/(N+1) amount, where X is the total amount left after each move, and N is the number of loosing cards remaining in the deck.

- IntwPrep December 03, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

So for each card you choose whether or not to bet? Is that the decision that you make?

- Anonymous July 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

for every card you should keep some +ve bet

- sse July 15, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

qouestion is not so clear that whether to bet all amount I am having a particular time or to bet a part of it as per my desire.

- dey July 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

It is as per your desire, but bet must be +ve amt.
and you must left with max. amount.

- sse July 15, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Assumption - we can bet any amount which is less than X

- 2n cards have to play
- So in first bet, I will use 2n/x amount.
- in worst case, if i am loosing in all first n bets
- again n+1 to 2n , all left cards are winning card.

Hence we can play with all cards, if starting amount is 2n/x.

- Anonymous July 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

interviewer is looking for max. amount, you will left at the end of game. is important.

- sse July 15, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Assuming that one can bet any amount between 0 and one's bankroll, the strategy maximizing the expected earnings is to bet 0 if there is at least one losing card remaining and everything otherwise.

Clearly if the remaining deck is all winning or all losing this is the optimal strategy. Otherwise, define Value(W, L) to be the value of a game with starting bankroll 1 and W winning cards and L losing. For all W > 0 and L > 0 we have the recurrence

Value(W, L) = max_{0 <= Y <= 1} (W/(W+L)) (1+Y) Value(W-1, L) + (L/(W+L)) (1-Y) Value(W, L-1).

The quantity being maximized is linear in Y, and clearly Value(W-1, L) < Value(W, L-1). Thus the optimum is Y=0.

- Anonymous July 07, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I got one approach for this,not sure if it is optimum.But with this algorithm in worst case also player will have more money at the end of the game what was with him at the begining.

1- Determine LossCount=n and WinCount=n
2- Determine the money to be bet.
a- If LossCount =0 then bet the whole money
b - Else devide the remaining money by (LossCount + 1)
3- Play the card.
a- If it is loss then LossCount-- and RemaningMoney = RemainingMoney - BetMoney.
b - Else WinCount-- and RemainingMoney=RemainingMoney+BetMoney
4- Go to Step 2 and repeat this till nth time.

Logic for choosig the divider as (LossCount +1) - We need to survive in the game till we start wining.Suppose we have X money and n win and n Loss chnaces.In worst case for the first nth time we lose.So for the next (n+1)th time we need minimum money to play.

- shaw.ravi July 08, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

It is horrible to put up ill-specified problems on such a useful forum . It wastes time. Moreover, the phrase in the problem "I solved it" is itchy. One must put good questions and realise that he solved it because he encountered it first

- Himanshu July 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

sorry bro, my intension is not to irritate/ demotivate any one.


I am so curious to know the answer.
this is the qn. asked in 4th round for 6+ yr. experienced.

- sse July 15, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

It wil be good to explain the problem statement clearly. My understanding is we have to pick one card from 2n cards and bet. Next time again we have to pick one card from 2n-1 cards and bet. So we have to pick and bet for all 2n cards. Am I right?

- Anonymous July 19, 2012 | Flag


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