Why do they ask these questions in interviews? These are super high difficulty. What are they trying to find out in the interviews by asking these questions. There is no way a person can solve these questions in an interview without prior preparation. It will take 1 week for a person who has never seen this question to come up with the solution.
Multiple reasons I would say. For example, it shows if the candidate has been preparing for that kind of questions. Personally, I would prefer pair programming with a person, or asking theoretical questions on how to solve the task. It is good that a person knows how to make a circular matrix, but pair programming will show me if he/she is up for work.
@@TheSolidsnake2001 this is so true competitive programming culture is easily catching up to the minds of these interviewers! Google and facebook started asking these type of questions and now even these fintech companies are not behind started following them!
You need to watch this video several times to understand it well. Try folks to trace it. This is a question asked in a Google coding interview! Thx Geeks4Geeks
Plz help any1 What is d role of 2 if conditions...?? I had ran d code without if conditions It worked successfully So what is the significance of that 2 if Conditions.... ???
I wish tutorial had used code with self descriptive names like k = topRow, l = leftColumn, n = rightColumn & m = bottomRow because I had to come back 3-5 times when the slide got changed into 1st part of the code But I found the description straight forward over the same explained in code school channel
you must elaborate more ..... now i have do a dry run see the function of if statements ......must include that also in explanation.... although its quite good ...i rate 7/10 ...
My teacher had given this program in assignment when I was in class 12th and at that time I tried a lot to solve this problem but didn't get right solution.😑
That's really cool solution, Reducing the array makes the logic more memorable
Yup
i was kicked out from the pi round of my interview for not able to print elements of the matrix in a spiral manner
Which company!
And were r u working now
Good Job ! Reducing the array at the end of every step is the key take away. Thanks for bringing it out. makes it easy to remember.
Why do they ask these questions in interviews? These are super high difficulty. What are they trying to find out in the interviews by asking these questions. There is no way a person can solve these questions in an interview without prior preparation. It will take 1 week for a person who has never seen this question to come up with the solution.
Some interviews expect you to do this in 30min
because these interviewers learned that other big tech companies asked question like this and they are just "monkey see monkey do."
Multiple reasons I would say. For example, it shows if the candidate has been preparing for that kind of questions. Personally, I would prefer pair programming with a person, or asking theoretical questions on how to solve the task. It is good that a person knows how to make a circular matrix, but pair programming will show me if he/she is up for work.
@@TheSolidsnake2001 this is so true competitive programming culture is easily catching up to the minds of these interviewers! Google and facebook started asking these type of questions and now even these fintech companies are not behind started following them!
stop engineering if you can’t solve
You need to watch this video several times to understand it well. Try folks to trace it. This is a question asked in a Google coding interview! Thx Geeks4Geeks
can u explain how to print array in matrix form
Thanks atlast i understood 👍👍
For those who dont get it try it in your computer along with a paper n pen
Plz help any1
What is d role of 2 if conditions...??
I had ran d code without if conditions
It worked successfully
So what is the significance of that 2 if Conditions.... ???
plZ tell me the code to find the sum of sub matrices within the original matrix
It is only valid for square matrix. Otherwise it would either repeat few elements or does not print few @geekforgeeks
For 3rd and 4th case, why do we need to write those if conditions?
it will tell how many elements in a row/column are remaining.
For e.g if you have a 2*6 matrix you don't have any column to print in reverse
m and n are the no of rows and columns, why do you keep saying it as ending row and column index??
Thanks a lot very simple explanation in short :)
Thanks for the appreciation naveen :)
Need better explanation, quite fuzzy!
could you do a video in java please
Nice solution BTW!!!
Can you please explain the logic to print a matrix in spiral form starting from center (printing outwards)?
Simple bro
Store all the values and print them in reverse order🤭
Charan Sai J sai I fixed it and thats not how it goes 🤫
the algorithm is working only when [m=n] but it's still a good one tho
how? can you explain pls
yes i agree, it is only valid for square matrix. Otherwise it would either repeat few elements or does not print few @geekforgeeks
@@Bhatonia_Jaat Suppose you take a rectangular matrix. e.g. 3x5, the condition for k
I wish tutorial had used code with self descriptive names like k = topRow, l = leftColumn, n = rightColumn & m = bottomRow because I had to come back 3-5 times when the slide got changed into 1st part of the code
But I found the description straight forward over the same explained in code school channel
Where is the value of m and n declared?
concept u explain is so easy to understand but when you explaining the code your blabbering that's makes it difficult sir
Thank you.
You're welcome suresh babu garine.
Thanks Sir
please solve using example while explaining code
Thanks
could have had better variable names....
class Solution
{
public:
vector spirallyTraverse(vector matrix, int r, int c)
{
int row = 0;
int col = 0;
vector output;
while(row
😆
I should start from 0 instead of 1
Very well explained
Bro thora frame karte waqt samjhate accha hota... Aise hi pehle se code likh liya aur bak diya
Except the last 2 if condition, everything was explained properly
import java.util.ArrayList;
import java.util.List;
import static java.lang.System.*;
public class PrintSpiralMatrix {
public static void main(String[] args) {
int[][] a = {
{1, 2, 3, 4, 5, 6},
{7, 8, 9, 10, 11, 12},
{13, 14, 15, 16, 17, 18}
};
int rows = a.length;
int columns = a[0].length;
//output expected -> 1,2,3,4,5,6,12,18,17,16,15,14,13,7,8,9,10,11
//travel
//left to right -> i=0,0 to 0,columns-1
//top to bottom -> i=0,columns-1 to rows-1,columns-1
//right to left -> i=rows-1,columns-1 to rows-1,0
//bottom to top -> i=rows-1,0 to 1,0
int i = 0;
int j = 0;
List visited = new ArrayList();
out.println("
rows : " + rows + "
columns : " + columns + ",");
while (rows > 0 || columns > 0) {
for (; j < columns; j++) {
if (visited.contains(i + "" + j))
break;
visited.add(i + "" + j);
out.print(a[i][j] + "|");
}
--j;
++i;
for (; i < rows; i++) {
if (visited.contains(i + "" + j))
break;
visited.add(i + "" + j);
out.print(a[i][j] + "|");
}
--i;
--j;
for (; j >= 0; j--) {
if (visited.contains(i + "" + j))
break;
visited.add(i + "" + j);
out.print(a[i][j] + "|");
}
++j;
--i;
for (; i > 0; i--) {
if (visited.contains(i + "" + j))
break;
visited.add(i + "" + j);
out.print(a[i][j] + "|");
}
++i;
++j;
rows = rows - 1;
columns = columns - 1;
}
}
}
Good solution but could have explained better
you must elaborate more ..... now i have do a dry run see the function of if statements ......must include that also in explanation.... although its quite good ...i rate 7/10 ...
My teacher had given this program in assignment when I was in class 12th and at that time I tried a lot to solve this problem but didn't get right solution.😑
Your teacher must've had some wild expectations seeing as this is a problem that normally appears in interview rounds of FAANG software corporations.
Thanks!!!
Class 12 ISC student
PA
Sir please make videos in hindi language + English notes. That would be better to understand.