Explanation for the article: www.geeksforgeeks.org/print-a-... This video is contributed by Harshit Jain. Read More: www.geeksforgeeks.org/print-a...
Пікірлер: 66
@shubham_skadam3 жыл бұрын
That's really cool solution, Reducing the array makes the logic more memorable
@gouravm49863 жыл бұрын
Yup
@RahulGupta-ly2uu6 жыл бұрын
i was kicked out from the pi round of my interview for not able to print elements of the matrix in a spiral manner
@Monkeydluffy-we2fk3 жыл бұрын
Which company! And were r u working now
@spk94345 жыл бұрын
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.
@neoblackcyptron4 жыл бұрын
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.
@leknubb3 жыл бұрын
Some interviews expect you to do this in 30min
@TheSolidsnake20013 жыл бұрын
because these interviewers learned that other big tech companies asked question like this and they are just "monkey see monkey do."
@NikitaKoselev3 жыл бұрын
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.
@omkarshendge54383 жыл бұрын
@@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!
@CleanDevelop3 жыл бұрын
stop engineering if you can’t solve
@hermesmercuriustrismegistu48414 жыл бұрын
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
@senthilkumaran53175 жыл бұрын
Thanks atlast i understood 👍👍 For those who dont get it try it in your computer along with a paper n pen
@naveenbv18386 жыл бұрын
Thanks a lot very simple explanation in short :)
@GeeksforGeeksVideos6 жыл бұрын
Thanks for the appreciation naveen :)
@vanshikakumar57396 жыл бұрын
can u explain how to print array in matrix form
@gyanasahu886 жыл бұрын
Need better explanation, quite fuzzy!
@sonalighoshal32125 жыл бұрын
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.... ???
@VishalYadav-sn3nn2 жыл бұрын
It is only valid for square matrix. Otherwise it would either repeat few elements or does not print few @geekforgeeks
@kishankavathiya81725 жыл бұрын
Nice solution BTW!!!
@kalaiselvichandrakasu27806 жыл бұрын
plZ tell me the code to find the sum of sub matrices within the original matrix
@pillulove4 жыл бұрын
m and n are the no of rows and columns, why do you keep saying it as ending row and column index??
@dhruva12214 жыл бұрын
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
@RaviYadav-bt2eg6 жыл бұрын
For 3rd and 4th case, why do we need to write those if conditions?
@adityapaithon64996 жыл бұрын
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
@dantewhite18185 жыл бұрын
could you do a video in java please
@wecan27293 жыл бұрын
class Solution { public: vector spirallyTraverse(vector matrix, int r, int c) { int row = 0; int col = 0; vector output; while(row
@rahularora37922 жыл бұрын
😆
@plamytommo78095 жыл бұрын
the algorithm is working only when [m=n] but it's still a good one tho
@Bhatonia_Jaat3 жыл бұрын
how? can you explain pls
@VishalYadav-sn3nn2 жыл бұрын
yes i agree, it is only valid for square matrix. Otherwise it would either repeat few elements or does not print few @geekforgeeks
@VishalYadav-sn3nn2 жыл бұрын
@@Bhatonia_Jaat Suppose you take a rectangular matrix. e.g. 3x5, the condition for k
@sureshgarine6 жыл бұрын
Thank you.
@GeeksforGeeksVideos6 жыл бұрын
You're welcome suresh babu garine.
@avtardeepsingh67152 жыл бұрын
Thanks Sir
@sabyasachisamadder36125 жыл бұрын
concept u explain is so easy to understand but when you explaining the code your blabbering that's makes it difficult sir
@cutepuppy-casper75612 жыл бұрын
Where is the value of m and n declared?
@tanujmishra23133 жыл бұрын
Thanks
@Centrix10004 жыл бұрын
Can you please explain the logic to print a matrix in spiral form starting from center (printing outwards)?
@charansaijuturu10763 жыл бұрын
Simple bro Store all the values and print them in reverse order🤭
@Centrix10003 жыл бұрын
Charan Sai J sai I fixed it and thats not how it goes 🤫
@divyanshbahuguna63246 жыл бұрын
Very well explained
@sujitamin9496 жыл бұрын
please solve using example while explaining code
@prabalshrivastava66333 жыл бұрын
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; } } }
@knseeker31935 жыл бұрын
Except the last 2 if condition, everything was explained properly
@manojsinghbhandari42803 жыл бұрын
I should start from 0 instead of 1
@BABEENGINEER4 жыл бұрын
could have had better variable names....
@sahilanower91895 жыл бұрын
Bro thora frame karte waqt samjhate accha hota... Aise hi pehle se code likh liya aur bak diya
@varungole34713 жыл бұрын
Good solution but could have explained better
@shwetankasingh18195 жыл бұрын
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.😑
@hasanrizvi20473 жыл бұрын
Your teacher must've had some wild expectations seeing as this is a problem that normally appears in interview rounds of FAANG software corporations.
@monuteotia36183 жыл бұрын
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 ...
@aakashchaudhary51714 жыл бұрын
Thanks!!!
@zRobi974 жыл бұрын
PA
@Kuldeep77203 жыл бұрын
Sir please make videos in hindi language + English notes. That would be better to understand.