Print 2-D array in spiral order

  Рет қаралды 229,070

mycodeschool

mycodeschool

Күн бұрын

Пікірлер: 179
@mr.mafeenychuggart2620
@mr.mafeenychuggart2620 9 жыл бұрын
This was the most straightforward and helpful explanation for a program in JAVA I have ever watched. Thank you very much for the excellent video tutorial!
@guffy1267
@guffy1267 9 жыл бұрын
thanks sir ! i am an android developer an i used to solve such problems past in my college days .. . this was amongst one question which i was not able to solve and then completely forgot . .. . ..thanks for such a wonderfull explanation . . i also visited your site to get amazed by such a wonderful spicy question to tickle my brain. . . THANKS AGAIN !
@harshitjain128
@harshitjain128 4 жыл бұрын
what are you doing now? where are you?
@vanshsehgal9475
@vanshsehgal9475 4 жыл бұрын
Ummm.. how was android development related to this talk...UHmmm Uhmmm...
@mandeepsharma8305
@mandeepsharma8305 7 жыл бұрын
A good teacher makes everything look simple.
@vivaanshah2870
@vivaanshah2870 4 жыл бұрын
Thank you so much!!!!! You've made such an HARD question seem like a piece of cake🍰
@prateekjain7785
@prateekjain7785 3 жыл бұрын
@Ari Neil what is this...? Why you write this comment on every comment box..?
@codingandmathvideos
@codingandmathvideos 10 жыл бұрын
You are great at explaining. Definitely better than any professor teaching at MIT, Stanford, Yale, Harvard , IIT, or whatever ivy league school out there. I had problems in my graph algorithms class. I can't wait till you do minimum spanning trees, breadth first search, depth first search, topological sorting, connected components, checking if a graph is cyclic ... all the good graph stuffs. Thanks in advance.
@karthikkedam6117
@karthikkedam6117 6 жыл бұрын
coding math Unfortunately, we lost him to an accident. He is very young and India's best coder..
@sagarjoshi7981
@sagarjoshi7981 6 жыл бұрын
@@karthikkedam6117 really 🙁 that's why there is no video on this channel for last 2 years...
@cut-a-lyst
@cut-a-lyst 5 жыл бұрын
@@karthikkedam6117 oh didn't knew this may his soul RIP
@himanshupoddar1395
@himanshupoddar1395 5 жыл бұрын
@@karthikkedam6117 common don't spread rumours, the founder name is Animesh Nayan and he is presently working at google.
@deancareers9639
@deancareers9639 5 жыл бұрын
@@himanshupoddar1395 the other guy died though , thats true. RIP :(
@mayankupadhyay6857
@mayankupadhyay6857 5 жыл бұрын
One of the best tutorial I have seen so far for prog. questions for interview!!
@ikashyap5
@ikashyap5 5 жыл бұрын
i can assure one thing that no one can explain things the way u do.. u are incredible !!
@gomzysharma
@gomzysharma 3 жыл бұрын
Give him a gold medal...he explained so well..I'll never forget now
@itspavi
@itspavi 8 жыл бұрын
You are the best....The work you are doing is helping so many. Please continue this.
@gladyouseen8160
@gladyouseen8160 5 жыл бұрын
the way u explained achieved my subscription. i loved ur explanation
@shubhamsonicse
@shubhamsonicse 8 жыл бұрын
thank you very much man. i am unable to understand this program from 4 hours. you helped me a lot
@lravikiran88
@lravikiran88 8 жыл бұрын
we can also implement the same using for loops
@gayatribagul2008
@gayatribagul2008 3 жыл бұрын
Y'll if you dont understand for the first time watch it again dont give up he explained this in genius way!
@jinhuang7258
@jinhuang7258 3 жыл бұрын
Thank you! Your explanation is so clear and straight to the point!
@jaafarskafi1
@jaafarskafi1 7 жыл бұрын
Thank you, sir. You are a god amongst men
@vaddimurthyram3364
@vaddimurthyram3364 3 жыл бұрын
You really made it in one piece..... Explanation was really awesome. Thanks for explaining this topic.
@Skyblade22
@Skyblade22 4 жыл бұрын
Ah yes, I failed an interview because of this question like 10 years ago... Thank you!
@madhurgupta9145
@madhurgupta9145 3 жыл бұрын
Very Sophisticated And Clear Explanation
@kakakukukakakuku
@kakakukukakakuku 8 жыл бұрын
so far the best explanation I have seen for this problem, thanks !
@yashkhatwani3198
@yashkhatwani3198 3 жыл бұрын
The explination is just amazing.Thanks
@FaridulIslam-cm5ij
@FaridulIslam-cm5ij 3 жыл бұрын
This is the best explanation i have ever seen
@Joyddep
@Joyddep 4 жыл бұрын
Best explanation so far!
@abocidejofa9686
@abocidejofa9686 11 жыл бұрын
You are simply the best. Please post more programming interview problems.
@arafattai9895
@arafattai9895 6 жыл бұрын
Very clear explanation and really easy to understand. Thank you for providing this video
@b_62_ayushmangupta82
@b_62_ayushmangupta82 4 жыл бұрын
Thanks a lot !!!! It really helps me a lot. It seems so difficult to me but u made it so simple.
@amanaswal11
@amanaswal11 4 жыл бұрын
Unbeatable Explanation.
@Notfcukedupyet
@Notfcukedupyet 3 жыл бұрын
Subscribed. Simple and elegant.
@estefaniac8260
@estefaniac8260 6 жыл бұрын
Thank you so much for your awesome video!!!!!! You made me understand this algorithm completely in a visual and clear way. :)
@gurmeetchawla8362
@gurmeetchawla8362 6 жыл бұрын
very well explained this is awesome. In the final code you just need to initialize the dir = 0 in the beginning. it seems, it was there in pseduo code but was missed in the final code.
@stocks4Trading
@stocks4Trading 3 жыл бұрын
Love you sir So much .....Made Such a hard question easy for us
@jatinkumar4410
@jatinkumar4410 4 жыл бұрын
Thank you sir for the help. This is one of the questions threatening me.
@shivakrishna8026
@shivakrishna8026 6 жыл бұрын
post some more questions..its really needed for this generation students and u r the best teacher
@gustavolopes5239
@gustavolopes5239 5 жыл бұрын
The final code, where you change the "dir" variable outside the "ifs" statements, you make the algorithm run longer (more iterations). If you change the "dir" inside the "ifs", the following "else if" could enter instantaneously, instead of needing another iteration. It probably won't change the execution time for small inputs, but the code is executing more comparisons (in the while statement: "L
@VirajChokhany
@VirajChokhany 4 жыл бұрын
Actually it will enter the else if only in the next iteration as at a time the 'else if' won't run if the 'if' runs.
@lakshaysharma8364
@lakshaysharma8364 4 жыл бұрын
just how simply you explained it pls complete the c++ course pls
@komalgujarathi8900
@komalgujarathi8900 6 жыл бұрын
perfect explaination and perfect solution
@montutpatel87
@montutpatel87 5 жыл бұрын
Superb explanation Guru. Thanks a lot.
@princeakhil208
@princeakhil208 5 жыл бұрын
What a wonderful explanation by @humblefool i am a fan to your teachings..!
@ivandrofly
@ivandrofly 9 жыл бұрын
Thank you so much fella, I think you were born to teach... **PS: You duplicated 2**
@tanmaysethi1373
@tanmaysethi1373 9 жыл бұрын
very very nice teaching skills.. u just made this difficult code very much easy to understand... thank you so much :)
@elinxxi
@elinxxi 7 жыл бұрын
clean like crystal, very good explanation.
@afridimajeed5897
@afridimajeed5897 4 жыл бұрын
Amazing explanation. The kind that I can think about what you said and try to convert it into code on my own. :)
@ajoras9197
@ajoras9197 2 жыл бұрын
Thank you soo much, since you made me to understand this code easily
@sasirekhamsvl9504
@sasirekhamsvl9504 4 жыл бұрын
perfect explanation bro
@xXNeoPivXx
@xXNeoPivXx 7 жыл бұрын
That was amazing, the code and the explanation, thanks for the videos, keep it up :D
@mihirvaghela3479
@mihirvaghela3479 3 жыл бұрын
realy helpfull after 8 years
@tuantranluuquoc2910
@tuantranluuquoc2910 5 жыл бұрын
I can see that this channel ain't get any new post anymore ! What a shame ! I've just found this one !
@TheVickiScott
@TheVickiScott 3 жыл бұрын
Great explanation. My code was similar but much more messy.
@manojpandey7517
@manojpandey7517 4 жыл бұрын
Only after watching this tutorial does this question feel much much easier.
@IChowdhury01
@IChowdhury01 3 жыл бұрын
This is absolutely brilliant, thank you.
@Dharmachinta1986
@Dharmachinta1986 11 жыл бұрын
Amazing....superb I need more practice at seeing you!
@sribharathgowru7625
@sribharathgowru7625 4 жыл бұрын
really a great explanation
@Codistency
@Codistency 3 жыл бұрын
op video...finally a very easy explanation
@anurag.tiwari.official
@anurag.tiwari.official 4 жыл бұрын
int main() { char this_video; printf("%c",this_video); } Output : Pure GOLD!
@lravikiran88
@lravikiran88 8 жыл бұрын
a good understanding of the matrix is important to understand the working logic
@manjun2095
@manjun2095 11 жыл бұрын
Nice, Clear explanation!! Thanks!!
@shoumikdebnath9142
@shoumikdebnath9142 5 жыл бұрын
It was very helpful.Thank you.
@kautukraj
@kautukraj 3 жыл бұрын
Very helpful!
@maxsteel4590
@maxsteel4590 9 жыл бұрын
You made it pretty easy to understand. Thanks
@souravsikaria4387
@souravsikaria4387 5 жыл бұрын
you are insane! thanks for such a beautiful explanation.
@surajtopal9940
@surajtopal9940 4 жыл бұрын
Thanks a lots sir jiiiiii🙏🙏🙏🙏🙏🙏🙏
@akshhatsrivastava1972
@akshhatsrivastava1972 4 жыл бұрын
Great explanation! Thank you!
@balrajjhaanand4863
@balrajjhaanand4863 3 жыл бұрын
Beautiful!
@ShinAkuma
@ShinAkuma 7 жыл бұрын
Thanks, this was so easy to understand.
@premkumarvasudevan6121
@premkumarvasudevan6121 2 жыл бұрын
Because the order of the directions (and hence the execution of the for loops) dont change, couldnot we get away with the directions variable altogether and only code just the for loops?
@cricketInsights614
@cricketInsights614 4 жыл бұрын
Can we do this by recursion also
@apnabharat4857
@apnabharat4857 8 жыл бұрын
very easy and simple explanation.......thanks !
@keshavraghav3896
@keshavraghav3896 4 жыл бұрын
why does compiler ignore the elements which are already printed. in the given code no such command is executed . so how do compiler prints only those numbers which have to be print?
@panchdevsingh
@panchdevsingh 7 жыл бұрын
Hi, may i know the tool you have used to create these videos, especially the writing pad?
@harshitsharma1104
@harshitsharma1104 4 жыл бұрын
Amazing Sir, Thank you so much.
@TANAYSPATEL
@TANAYSPATEL 11 жыл бұрын
VERY VERY THANK YOU.....it's help me lot to understand this problem....!!!
@sachinbhalla14
@sachinbhalla14 5 жыл бұрын
Great Explanation
@rediscoveryourself5956
@rediscoveryourself5956 7 жыл бұрын
def matrixRot(matrix): row,col=np.shape(matrix) temp=np.empty(shape=[row,col]) for i in range(row): for j in range(col): temp[i,col-1-j]=matrix[j,i] return temp
@adityaverma6733
@adityaverma6733 5 жыл бұрын
great video from our iiita alumni :)
@TheIndianDev
@TheIndianDev 7 жыл бұрын
u r amazing in explaining things :*
@indian8701
@indian8701 8 жыл бұрын
Can this be done using recursion??
@vanshikasharma8958
@vanshikasharma8958 2 жыл бұрын
Explained so well! Though I'm encountering a problem of how to find the number of rows and columns if and 2d array is given. The one I found on internet makes my code fail so , Could anyone please help me out?
@raj_kundalia
@raj_kundalia 2 жыл бұрын
Amazing. Thank you!
@lavanyarao5650
@lavanyarao5650 4 жыл бұрын
great explanation thanks a lot!!
@sparshgupta2931
@sparshgupta2931 4 жыл бұрын
What was is the use of dir here??
@SniperofDoomFromKong
@SniperofDoomFromKong 7 жыл бұрын
For anyone else that was wondering if you can delete the direction variable and the if statements: you can't. Try the case with an 8x1 matrix, i.e. a matrix with 8 rows and 1 column. It won't work there.
@jaychou9256
@jaychou9256 2 жыл бұрын
Yeah, I suppose we should re-consider the boundary everytime before we go into the four if statements.
@rupesh0541
@rupesh0541 4 жыл бұрын
Hi, without direction tracking it is also working fine because 4 separate loop. can you please write some edge case where without direction tracking it will fail? Thanks for good explanation as always :)
@Chris-cs7nv
@Chris-cs7nv 2 жыл бұрын
I think it always works because we always go left-right, top-bottom, right-left, and bottom-top we just need to update left, right, bottom and top accordingly after going one direction. I could be wrong but that's what I see and understand.
@brokenxsticker
@brokenxsticker 6 жыл бұрын
This only seems to work if the matrix is a square (same number of rows as columns). What would you change to make it work on a matrix with 3 rows and 4 elements in each row.
@chandrasekharmamidi2236
@chandrasekharmamidi2236 5 жыл бұрын
i am getting a error of13 { C:\Users\hp\Desktop\mcs\spiral print of an 2-d array.cpp [Error] invalid types 'int[int]' for array subscript}. it was repeating for the four printing for loops.and another error was {C:\Users\hp\Desktop\mcs\spiral print of an 2-d array.cpp [Error] cannot convert 'int (*)[50]' to 'int*' for argument '1' to 'void spiralprint(int*, int, int)'} while making the function call spiral print with arguments (a,m,n). can you please resolve it.
@prachimittal7854
@prachimittal7854 4 жыл бұрын
can you please tell how to print the spiral in inside out format
@devaentgs9957
@devaentgs9957 4 жыл бұрын
One of the ways can be, adding elements to a stack as we traverse from outside in. Print the contents of the stack.
@riteshbajaj6
@riteshbajaj6 11 жыл бұрын
super clear.....thnks
@unhappysisyphus
@unhappysisyphus 8 жыл бұрын
Do we even need to have a direction variable and the if-else checks?As the spiral always goes in a regular fashion,why not just write the code for each direction in the direction of the spiral in the while loop without checking the direction ?
@SurbhiShah16
@SurbhiShah16 8 жыл бұрын
Did you figure out why do we need direction variable?
@unhappysisyphus
@unhappysisyphus 8 жыл бұрын
You don't
@nakulmohan115
@nakulmohan115 7 жыл бұрын
I had written a code that had no direction variable. All the directions were executing in a single while loop. The problem with that is that sometimes you need to skip some directions and execute others. So, you'll need to add checks in the for loops so that elements do not get printed twice. This solution is much cleaner as required checks are being executed every time the loop is run . You can try writing code without the direction variable. It would work, but won't be this clean.
@gururajkoti5672
@gururajkoti5672 7 жыл бұрын
Direction variable is required, try executing for matrix of 1X8 dimension without direction variable
@yeeteshpulstya9890
@yeeteshpulstya9890 6 жыл бұрын
rows = 1 cols = 8 matrix = [[1,2,3,4,5,6,7,8]] T,B,L,R = 0,rows - 1,0,cols - 1 while(T < B): for i in range(L,R+1): print(matrix[T][i], end = ' ') T += 1 for i in range(T,B+1): print(matrix[i][R], end = ' ') R -= 1 for i in range(R,L-1,-1): print(matrix[B][i], end = ' ') B -= 1 for i in range(B,T-1,-1): print(matrix[i][L], end = ' ') L += 1 Python code for the problem without direction variable, works for 1X8 matrix as well. So no, we do not need the direction variable.
@sungyunchung1102
@sungyunchung1102 8 жыл бұрын
I just want to check its time complexity and space complexity. Though there is an inner for loop for one-time-while loop, the number of inner for loop is always constant for each while loop iteration. Therefore, I assume the time complexity can be O(n) but I am not quite sure. Also I think space complexity would be O(1) because we don't use any extra space. Can you correct me if I am wrong? Thanks!!
@josephralph7640
@josephralph7640 8 жыл бұрын
Sung Yun Chung Time complexity is O(mn), since we are visiting each element once and there are mn elements in the array.
@ImranAliyev
@ImranAliyev 6 жыл бұрын
it was amazing explanation!
@niti_sha_jain
@niti_sha_jain 4 жыл бұрын
It works only for n==m ? because when I apply this algo on 3*4 matrix it failed
@devaentgs9957
@devaentgs9957 4 жыл бұрын
It works for 3*4 as well.
@lomeshdaheria9960
@lomeshdaheria9960 3 жыл бұрын
Thanks bhai👍😀
@MilindGupta
@MilindGupta 3 жыл бұрын
I used the exact same code but it's printing main diagonal only on GFG... Kindly check the code // { Driver Code Starts #include using namespace std; // } Driver Code Ends class Solution { public: vector spirallyTraverse(vector matrix, int r, int c) { // code here int dir=0 ; int top=0,left=0,bottom=r-1,right=c-1; vectorans; while(top
@varadharajanr1452
@varadharajanr1452 9 жыл бұрын
Simple & best!!!
@amittapas2429
@amittapas2429 5 жыл бұрын
You can use the switch statement for directions, to make the code a little more elegant!
@anurandutta2217
@anurandutta2217 4 жыл бұрын
Time complexity?
@hitec1691
@hitec1691 5 жыл бұрын
simply beautiful :)
@igotapochahontas
@igotapochahontas 6 жыл бұрын
Why are b and r -1? I don't get that...is that because arrays start at [0]?
@gururajkoti5672
@gururajkoti5672 8 жыл бұрын
Nicely explained
@rahulpise1840
@rahulpise1840 9 жыл бұрын
Sir can u publish the the video on printing pattern like pyramid or any specific pattern?
@wpavada3247
@wpavada3247 8 жыл бұрын
Another way to do the same is writing a formula to find the ith element in the spiral form.
@jasminekaurkheterpal9224
@jasminekaurkheterpal9224 4 жыл бұрын
can someone explain me the while condition
@anksPBN
@anksPBN 9 жыл бұрын
great ! thanks for the detailed videos
@abocidejofa9686
@abocidejofa9686 11 жыл бұрын
I love how you think to solve problems. How do I develop this type of skills? Can you also solve a N by N tic tac toe? also Sudoku?
@mycodeschool
@mycodeschool 11 жыл бұрын
You need to practice and solve a lot of problems. That's it. :) Yeah, we will get some more in this series.
How many times is a sorted array rotated?
13:03
mycodeschool
Рет қаралды 172 М.
Pointers and 2-D arrays
12:19
mycodeschool
Рет қаралды 488 М.
Don’t Choose The Wrong Box 😱
00:41
Topper Guild
Рет қаралды 62 МЛН
Mom Hack for Cooking Solo with a Little One! 🍳👶
00:15
5-Minute Crafts HOUSE
Рет қаралды 23 МЛН
Search element in a circular sorted array
12:22
mycodeschool
Рет қаралды 124 М.
Know your data type: int - C Programming Tutorial 08
23:03
mycodeschool
Рет қаралды 237 М.
How to Remember Everything You Read
26:12
Justin Sung
Рет қаралды 3,6 МЛН
Quicksort algorithm
20:39
mycodeschool
Рет қаралды 1,8 МЛН
A Prime Surprise (Mertens Conjecture) - Numberphile
9:56
Numberphile
Рет қаралды 843 М.
Find merge point of two linked list
12:48
mycodeschool
Рет қаралды 108 М.
Don’t Choose The Wrong Box 😱
00:41
Topper Guild
Рет қаралды 62 МЛН