We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Hello, I practised the same mechanism as you did above and my sample test cases are passed but getting wrong answer for test cases once i submit it. Please help.
void matrix_rotation(long *input, long r)
{
int start_i=0, count;
int start_j=0;
int row=max_row;
int column=max_column;
int size=2*row+2*(column-2);
while(start_i<max_row/2 && start_j<max_column/2)
{
r=r%size;
count=0;
long arr[size];
for(int j=start_j; j<column; j++)
arr[count++]=input[start_i*max_column+j];
for(int i=start_i+1; i<row; i++)
arr[count++]=input[i*max_column+column-1];
for(int j=column-2; j>start_i-1; j--)
arr[count++]=input[(row-1)*max_column+j];
for(int i=row-2; i>start_i; i--)
arr[count++]=input[i*max_column+start_j];
//copying back to main input
count=r;
for(int j=start_j; j<column; j++)
{
count=count%size;
input[start_i*max_column+j]=arr[count++];
}
for(int i=start_i+1; i<row; i++)
{
count=count%size;
input[i*max_column+column-1]=arr[count++];
}
for(int j=column-2; j>start_i-1; j--)
{
count=count%size;
input[(row-1)*max_column+j]=arr[count++];
}
for(int i=row-2; i>start_i; i--)
{
count=count%size;
input[i*max_column+start_j]=arr[count++];
}
start_i++;
start_j++;
row--;
column--;
size=2*(row-1)+2*(column-3);
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Matrix Layer Rotation
You are viewing a single comment's thread. Return to all comments →
Hello, I practised the same mechanism as you did above and my sample test cases are passed but getting wrong answer for test cases once i submit it. Please help.
void matrix_rotation(long *input, long r) {
}