Microsoft interview question

Diagonally flip a two dimensional array.

Interview Answers

Anonymous

Feb 17, 2012

I will not write the code I will just post the solution. The code is straightforward. Observation: - in order to talk about diagonals in a two dimensional array, that means that we are dealing with a (n x n) array (square matrix) Solution: - flip on the first diagonal (i = j): (i, j) (j, i) - flip on the second diagonal (i + j = n): (i,j) (n - j, n - i) To write the code should be straightforward. Be careful to flip only half of the matrix :) and not all the elements!

Anonymous

Apr 20, 2020

flip on second diagonal n-j+1,n-i+1