Microsoft Interview Question for Software Engineer in Tests






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

use XOR.
XOR numbers of cards = missing card number
XOR colors of cards = missing card color
XOR of suites of cards = missing card suite.

XOR(A, A) = 0

and if u do XOR on even times repeated no.s we will get zero.
and if u do XOR on all even times and one no. odd times then we will get odd time repeated no.

Here, in our case... missing no. repeated odd no. of times n other no. repeated even no. of times.
So, our XOR will work here.

plz correct me if I'm wrong...
Thanks

- chait November 30, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

this solution seems better!!!

- sameer December 23, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I am RayWJ and I approve this approach!

- RayWJ September 16, 2011 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

sum of all face values - sum of the given deck = missing card.
Time=O(n). Space=O(1)

- chennavarri October 18, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

That would help find the face value of the missing card. But how would you find the suite then?

- someone October 18, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

use four more variables to count the suites. if(suite[i]!=13) then ith suite

- chennavarri October 18, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

use hashing to find suite

- Anonymous October 18, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Yeah Hashing sounds like the best option. Have a hashmap consisting of key = suite and value = sum. Go through the given deck entirely once and keep adding face value to the corresponding suite entry from hashmap. When you look at the hashtable you'll immediately know which card and which suite is missing. Only problem with this is that you'll need 4 variables.

- someone October 23, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Assign multipliers for each suite as;
spade: 100
club: 1000
diamond: 10000
heart: 100000

Add the values by multiplying card value with the suite multiplier.
Find the difference between the sum of 52.
In this way both the value and the suit can be found.

for ex:
If the difference is 300000, missing card is heart_3

Note: In order to avoid collision, do not use the value of 10. Set card value for jack as 11 (not 10), queen 12 etc..

Space complexity: O(1)
No need for an extra container

- erm October 18, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

V.nice solution

- Metta October 19, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Hearts : *100
Spades : *1000
If so then 10 of hearts and 1 of spades both evaluate to 1000. Here is a collision.
Instead, i recommend use of distinct prime numbers beyond 15 as multiples. 17,19,23,29

- Vinay Vasyani October 23, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I meant beyond 13. (not 15)

- Vinay Vasyani October 23, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Actually i had added the note about how to prevent the collision case:

"Note: In order to avoid collision, do not use the value of 10. Set card value for jack as 11 (not 10), queen 12 etc.."

Correction on the note: "... Set the card value for 10 as 11 (not 10), jack: 12, queen: 13 and the King: 14

- erm October 30, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think there should be small change to ern solution to avoid collisions, where 10*100(Hearts, 10) == 1*1000(Club, 1).

So taking

spade: 1
club: 100
diamond: 10000
heart: 1000000

would be the correct solution. Please crrect me if i am wrong,

Thanks,
Satya Chaganti.

- Satya Chaganti November 03, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think there should be small change to ern solution to avoid collisions, where 10*100(Hearts, 10) == 1*1000(Club, 1).

So taking

spade: 1
club: 100
diamond: 10000
heart: 1000000

would be the correct solution. Please crrect me if i am wrong,

Thanks,
Satya Chaganti.

- Satya Chaganti November 03, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think there should be small change to ern solution to avoid collisions, where 10*100(Hearts, 10) == 1*1000(Club, 1).

So taking

spade: 1
club: 100
diamond: 10000
heart: 1000000

would be the correct solution. Please crrect me if i am wrong,

Thanks,
Satya Chaganti.

- Satya Chaganti November 03, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think we can also use Multipliers such as
Hearts = 1
Spade = (Heart * 13) + 1
Club = (Spade * 13) + 1
Diamond = (Club * 13) + 1

Assuming the suite starts from A = 1 and ends in King = 13
When we subtract the sum from the original sum and get the diff,
if(diff % club == 0)
missing card is of the value (diff/club) in the suite "club"

- anon October 20, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Hearts = 1
Spade = Heart * 13
Club = Spade * 13
Diamond = Club * 13

Why plus 1?

- yingying October 20, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

because
King of Hearts = 1 * 13
Ace of Spade = 13 * 1
They give the same product. So, to be safe, we choose multipliers such that maximum product of a suite is less than the minimum product of the next suite. In other words,the LCM of two suits (eg: spade and club) will be always higher than highest multiple of club.

- anon October 23, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Why is it necessary to multiply? Can't we just use:
0: Hearts 1 - 13
1: Spade 14 - 26
2: Club 27 - 39
3: Diamond 40-52.

Then sum up 1 to 52. If n = sum - givenSum, then suit is n / 13, card number is n%13.

- ishtiaq.jishan November 04, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

nice solution.. :)

- Anonymous January 15, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

use a dict to map the missing card.

- weijiang2009 February 06, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Groom Lake, Nevada = Area 51 (they ain't playing with a full deck) PS- the question says the deck is 51, so one missing from a deck of 51 is 50 cards.

- Dan Ronyak June 14, 2013 | 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