Skip to main content

Posts

Showing posts from May, 2018
Rotate the Matrix: You are given a NxN matrix.You have to rotate same coloured rectangle clockwise or anticlockwise alternatively by a ‘k’ value. K value keeps on increasing by one as we move from outer to inner loop.Suppose in the given figure outermost loop is rotated by 1 place clockwise followed by next loop rotated by 2 places anticlockwise and so on. [Give only Inplace solution]. // Picture taken from :  https://www.geeksforgeeks.org/factset-interview-experience-set-12-campus/ Solution: #include <iostream> using namespace std; #define N 5 void printMatrix (int A[][N]){     for(int i=0; i<N; i++){         for(int j=0; j<N; j++)             cout<<A[i][j]<<' ';         cout<<endl;     }     } void rotateMatrix (int A[][N]){     int l = 0, r = N-1, t = 0, b = N-1;     int k = 1; ...