## Microsoft Interview Question for Software Engineer / Developers

• 0

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

``A[i][j] = A'[M-j-1][i]``

Comment hidden because of low score. Click to expand.
0

when j = 3 ( as M = 3) what will be the result?

Comment hidden because of low score. Click to expand.
0

j by definition is >= 0 and < M

Comment hidden because of low score. Click to expand.
0

@ahj this is really correct answer
A[i][j] = A'[M-j-1][i]

one quick question however...
apart from creating and observing this pattern... is there any other way.. algebric to reach this answer

Comment hidden because of low score. Click to expand.
0

I have the same question in mind.

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

A[i][j] = A[N-j][i]

Comment hidden because of low score. Click to expand.
0

A[i][j] = A[N-j-1][i]

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

The relation will be,
A[i][j] = A'[M-j+1][i]

Comment hidden because of low score. Click to expand.
0

here M=3
so ur solution is wrong..

Comment hidden because of low score. Click to expand.
0

@saumils1987 Could you please tell me in which case this will give incorrect result?

Comment hidden because of low score. Click to expand.
0

A[i][j] = A'[M-j][i]
This is the right solution

Comment hidden because of low score. Click to expand.
0

A[i][j] = A'[M-j+1][i] is wrong
Here M = 3, and N= 2
using above relation A[0][0] =A'[4][0]

So,
A[i][j] = A'[M-j][i] is correct answer

Comment hidden because of low score. Click to expand.
0

@gang
A[i][j] = A'[M-j][i] is not correct. take i = 0 and j = 0;
A[0][0] = A'[3][0] but only 3 rows but not 4 in A'
I think the answer is A[i][j] = A'[N-j][i]
correct me if i'm wrong

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

Rotation is equal to a transpose, followed by a "flop" around the horizontal axis:
A[i][j] => A[j][i] => A[M-j-1][i]
provided the first set of brackets correspond to the column number and the indexes starts at 0

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

Everything was written before is wrong. That's right
A[i][j] => A'[M - j][N - i - 1]

Comment hidden because of low score. Click to expand.
0

including yours...

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

interoper ur solution is wrong as well ..
only ahj's solution si correct..

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

Given N=2,M=3
The relation between A[] and A'[] is
A[i][j]=A'[(N*(j+1))%M][i]

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

Surprised so many people got wrong for such a simple question
Ah's solution is the only right one

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

A[i][j] = A [M-j+1][i]

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

A[i][j] = A [M-j+1][i]

A[i][j] = A[j][M-i+1]

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

A[N][M] = A'[M][N] only that M decreases.

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

its A[N-j-1][i] not A[M-j-1][i]

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

A[i][j] = A'[2-j][i]

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

A[i][j] = A'[N-j][i]

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

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

A'[i][j] = A[j][i]
A'[i][j] = A'[M-1-i][j]
where i ranges from 0 - M/2
and j ranges from 0-N

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

A[i][j] = A'[N-j+1][i]

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

I got that A' is the result of the rotation on A in a anti clockwise manner. Could anyone please explain the problem?

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

A[i][j] = A'[N-j][i]

Comment hidden because of low score. Click to expand.
0

It is like cycle detection algorithm:
Lets say in initial matrix (row,colun) -> (i,j)
So now index in array = COLS * row + column.
Now the same index after transition will be index = ROW*col + row.
That is in the trasitioned matrix row and columns are interchanged and also the new matrix order is also reversed.

Ex (1,2,3,4,5,6) becomes now (1,4,2,5,3,6) (Represented in a 2 X 3 matrix)
But from the question these are again reversed.

So ow the solution becomes
newi = (COL - ROW*col + row) / COL
newj = ( COL - ROW*col + row.) / COL

This logic might be complex , If some one has a better logic please share

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

It is like cycle detection algorithm:
Lets say in initial matrix (row,colun) -> (i,j)
So now index in array = COLS * row + column.
Now the same index after transition will be index = ROW*col + row.
That is in the trasitioned matrix row and columns are interchanged and also the new matrix order is also reversed.

Ex (1,2,3,4,5,6) becomes now (1,4,2,5,3,6) (Represented in a 2 X 3 matrix)
But from the question these are again reversed.

So ow the solution becomes
newi = (COL - ROW*col + row) / COL
newj = ( COL - ROW*col + row.) / COL

This logic might be complex , If some one has a better logic please share

Comment hidden because of low score. Click to expand.
0

Sorry newJ = ( COL - ROW*col + row.) % COL

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.

### 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.