Microsoft Interview Question for Software Engineer / Developers






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

ok here is the series I found.

it is only possible when n is odd her in your case it is 5.

(n+1)/2 , n, (n-1)/2, n-1, (n-3)/2, n-2, .............and goes on like this

so 0th iteration C
so 1th iteration E
so 2th iteration B
so 3th iteration D
so 4th iteration A

and repeats the same .......
FYI: stack revert backs to original after n iterations.

- Aditya March 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

it can not end up like : E-D-C-A-B no matter how many procedure were repeated

Because procedure does not change the order of those 5 boxes, it just like move the header pointer in the looped link list

- irobert November 04, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

ABCDEABCDEABCDEABCDEABCDEABCDE
^ ^ ^

Stack from the position ^.
Each operation = move Stack beginning position forward 2 chars.
For k times operation, the middle element ='C'+(2*k)%5

- irobert August 01, 2010 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

stack ?? how could we remove from bottom side of the stack???

- Anonymous December 01, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

simple array rotation and mod operation problem: (2*3)%5 = 1 --> answer Box B

- geniusxsy November 02, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

wrong answer ...

following formula gives the index of first element after n rotations,

total = total number of elements in array
n = number of rotations

(total - ((n % total) - 1))

for this problem, there are 3 iterations and each iteration rotates the array by 3, so

(5 - (((3 * 3) % 5) - 1)) = 2, the top element is 'B'

so, the middle element is 'D'.

- Big N November 19, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

so by your method after 2 rounds top element should be B

because as per your formula:(5-(((2*2)%5)-1)) =2 thus the top element is B but its actually E so better check it

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

but for each iteration there will be 3 rotations
so, it will be (5-(((3*2)%5-1)) = 5,so top element will be E after 2 rounds
so i think Big N's formula is right

- sa shah June 04, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Hey Big N... ya your formula working fine... will you do me a favor by explaining how you have arrived at this one.... becoz tat matters the most na.... even it may be thought provocking to someone seeing this post... :)

- krishnaraj92 June 30, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

"placed on top with their vertical order maintained", so it is not a rotation.

- foolysx November 03, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

you just didn't get enough Vitamin, Zinc, Iron... when you grew up?

- geniusxsy November 04, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Iteration 1: ABCDE becomes CDEAB
Iteration 2: CDEAB becomes EABCD
Iteration 3: EABCD becomes BCDEA

D is in the middle

- karthikvaidy November 05, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I got the same answer.

- Vaishnavi November 08, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I agree with Karthik.
A C E B
B D A C
C E B {D}
D A C E
E B D A

- Prayag K Iyer November 14, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Thats correct !

- Anonymous October 28, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

element index after n round = (index_of_variable + 2 * number_of_rounds) % size

At start middle element was C
Therefore, 3 (C's index) + 2 * 3 = 9 %5 = 4

- Anonymous December 04, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

please mention how are you reaching to that mathematical eq.?

- help me February 28, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Let n be the no of iterations and initial stack be numbered as :
A 1
B 2
C 3
D 4
E 5

mid position = 3
Let "pos" be the position which is at "mid" after 'n' iterations. Then we have

(pos + 3*n)%5 = 3

3 in LHS is because 3 positions are shifted in each iterations and 3 in RHS is for mid.

- vagrawal13 June 25, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Initially ABCDE
Next CDEAB Next EABCD Next BCDEA...
Hence order is E then third element from E going upwards i.e. B
then third element from B i.e. D
then third element from D i.e. A
then third element from A i.e. C
then third element from C i.e. E (all these counting based on original order)
and can be generalized so on.

- Sharma April 08, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The simplified solution is to do circular right shit 3 times multipled by number of iterations
>>>2*3 and extract the middle element.
Programmatically you would need extra Stack and a Queue

Algorithm would be like the following

S2.push(S1.pop());
S2.push(S1.pop());
Q2.Enqueue(S1.pop());
Q2.Enqueue(S1.pop());
Q2.Enqueue(S1.pop());

S1.Push(S2.pop());
S1.Push(S2.pop());
S2.push(Q2.dequeue());
S2.push(Q2.dequeue());
S2.push(Q2.dequeue());
S1.Push(S2.pop());
S1.push(S2.pop());
S1.push(S2.pop());

Repeat the above procedure n times for n iterations. Implement the stack with an array has backing store and get the middle element.

- skondoji March 12, 2014 | 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