https://practice.geeksforgeeks.org/problems/cd61add036272faa69c6814e34aa7007d5a25aa6/1/?track=30-DOC-day-5&batchId=320#
check this link why i am failing test cases bu use of this function int num=n*m;
int arr[num];
int sr=0;
int sc=0;
int er=n-1;
int ec=m-1;
int x=0;
while(sr<=er and sc<=ec){
for(int i=sc;i<=ec;i++){
arr[x]=a[sr][i];
x++;
}
sr++;
for(int i=sr;i<=er;i++){
arr[x++]=a[i][ec];
}
ec–;
if(er>sr){
for(int i=ec;i>=sc;i–){
arr[x++]=a[er][i];
}
er–;
}
if(ec>sc){
for(int i=er;i>=sr;i–){
arr[x++]=a[i][sc];
}
sc++;
}
}
return arr[k-1];
https://ide.codingblocks.com/s/415392
Spiral print .......................challenge
Hello @poojadas408 which question you are doing ?
are you doing from hackerblocks or gfg because the link which you have shared above is not opening.
its from gfg ,Ques-Given a matrix of size N x M. You have to find the Kth element which will obtain while traversing the matrix spirally starting from the top-left corner of the matrix.
could you please share the correct link of that?
check this:
i have commented the mistake:
Happy Learning!!
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.