Microsoft Interview Question for Interns


Country: India
Interview Type: In-Person




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

Have an int double array (n x n)
For every row and column, have three extra fields
1. Corrupted (If this row or column is filled by both players atleast once)
2. First move (Who filled the row/column first - 1 or 2)
3. No.of blocks filled (Count)
All are initialized to zero. You have player1 and player2
When a player makes an entry, you have to check those 3 variables in corresponding row and column. Follow the following steps:
1. If corrupted is true, you need not worry
2. If the person who made the move now != first person, corrupted = true and jump off
3. No.of blocks++ , If no.of blocks == N, this player has won. End of story :D

- Neerad October 24, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I did consider explaining diagonals, its trivial

- Neerad October 24, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

If you are already checking for sum==N, whats the need of first 2 checks?

- Srikant Aggarwal October 28, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

2. If the person who made the move now != first person, corrupted = true and jump off
3. No.of blocks++ , If no.of blocks == N, this player has won. End of story :D

can u please elaborate these two points

- Siva krishna November 09, 2012 | Flag
Comment hidden because of low score. Click to expand.
5
of 7 vote

Use NxN int matrix and 2N + 2 integers representing the sum of N cols, N rows and 2 diagonals.
Player 1's choices will be marked as 1.
Player 2's choices will be marked as -1.
Add that mark (+-1) to the relevant row/col/diag counters.
Player 1 wins if after adding the mark the row/col/diag is sum is N.
Player 1 wins if after adding the mark the row/col/diag is sum is -N.
They draw if matrix is full.

Calculating game result is immediate.

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

Player 2 wins if after adding the mark the row/col/diag is sum is -N. **

- avico81 November 06, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

exactly the solution i thought. Any way to improve upon it?

- sahil.bathla1 November 12, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

we can use 2D matrix intialised with zeros and then when ever a player plays make the corresponding entry to be equal to 1,..winning condition is class that does the job of row sum...it can store the row sum and use it later...

- sharda October 24, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

For every row/column, maintain a field called SUM. When player 1 marks, add 2 to the sum, when player2 marks, add 5 to the sum. If the sum ever reaches 2*N, then player 1 win, If the sum reachers 5*N, then player 2 wins. We only need to check/update the sum for the row/column where the last player has played.

Note: instead of 2,5 we can use any two numbers which are relatively prime.

- cijo.thomas October 25, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Hey, you are checking for 2N and 5N to know if a row is filled. Assume N 5. so you check for 10 or 25. if user 2 has filled twice and remaining all are unfilled (0) then the sum is 10 which will be 2*N as per your checking and your logic will return that user 1 has won...

- Raghavendra October 26, 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