LeetCode Spiral Matrix Solution Explained - Java

  Рет қаралды 49,724

Nick White

Nick White

Күн бұрын

Пікірлер: 56
@dediprakasa2162
@dediprakasa2162 5 жыл бұрын
Now I understand where those ifs come from. Thank you!
@sydneystriker5355
@sydneystriker5355 3 жыл бұрын
Same Here. THUMBS UP!
@atift5465
@atift5465 5 жыл бұрын
I live how you explain so thoroughly and use brute force thats understandable and not too optimal to get! Thanks!!
@brentleyrandy4950
@brentleyrandy4950 3 жыл бұрын
you all probably dont give a shit but does anyone know a way to get back into an Instagram account..? I was stupid lost my login password. I would love any tricks you can offer me.
@kolefabian6264
@kolefabian6264 3 жыл бұрын
@Brentley Randy instablaster :)
@brentleyrandy4950
@brentleyrandy4950 3 жыл бұрын
@Kole Fabian I really appreciate your reply. I found the site thru google and im trying it out now. Takes quite some time so I will reply here later with my results.
@brentleyrandy4950
@brentleyrandy4950 3 жыл бұрын
@Kole Fabian It worked and I finally got access to my account again. I am so happy! Thanks so much, you really help me out :D
@kolefabian6264
@kolefabian6264 3 жыл бұрын
@Brentley Randy You are welcome :D
@jugsma6676
@jugsma6676 4 жыл бұрын
Of all the videos I watched so far, this one is well explained.
@dhanpalharikumar6192
@dhanpalharikumar6192 6 ай бұрын
true ;)
@harinaaraayans3453
@harinaaraayans3453 5 жыл бұрын
great job dood. keep doing this
@strawberriesandcream2863
@strawberriesandcream2863 2 жыл бұрын
thanks for helping me understand how to solve this problem!!
@codingchey
@codingchey Жыл бұрын
I dont know anything about coding but the coco powder almonds are really good! Thanks for the suggestion Nick!!
@PssGameplayER
@PssGameplayER Жыл бұрын
Really great video. Helped a lot to understand the problem and look for a solution. I was able to solve it using the approach you showed in rotating the matrix.
@PssGameplayER
@PssGameplayER Жыл бұрын
class Solution { fun spiralOrder(matrix: Array): List { val result = mutableListOf() var l = 0 var r = matrix.first().size - 1 val totalSize = matrix.size * matrix.first().size while (l
@PssGameplayER
@PssGameplayER Жыл бұрын
but looks like your solution is much faster
@sahilanower9189
@sahilanower9189 3 жыл бұрын
Great.... Thumbs up to the clearity of your explanations!
@samermazraani9011
@samermazraani9011 4 жыл бұрын
very well explained especially descriptive variable names make it easier
@devyanigera
@devyanigera 5 жыл бұрын
Thanks this is great explanation and variable naming!
@abisoyelawal9810
@abisoyelawal9810 5 жыл бұрын
I like how you use descriptive variable names instead of i and j
@georgechen1124
@georgechen1124 5 жыл бұрын
Nick is the best!
@kashafmujeeb3690
@kashafmujeeb3690 2 жыл бұрын
What is the time and space complexity for this solution?
@flamboyanz
@flamboyanz 5 жыл бұрын
Good one! It made it very easy! Thank you
@GuitaristVoyage
@GuitaristVoyage 2 жыл бұрын
can u explain the if check inside whike loop
@MichaelSalo
@MichaelSalo 4 жыл бұрын
I attempted to do it in a single loop, with some logic to decide what direction the spiral is moving. It works but took me a while and doesn't perform as well as the above.
@somewheresomeone3959
@somewheresomeone3959 Жыл бұрын
Great way to understand! Thank you!
@lifeofme3172
@lifeofme3172 4 жыл бұрын
It's a fun problem. Thanks Nick 😊
@satyamgupta6030
@satyamgupta6030 Жыл бұрын
what a nice explaination thanks a ton brother. please keep making such videos.
@favrito495
@favrito495 3 жыл бұрын
You are awesome bro.!! Love from India
@kamalpreetsingh4782
@kamalpreetsingh4782 4 жыл бұрын
As always great work sir 👍
@nathann4291
@nathann4291 5 жыл бұрын
great work, what's the time complexity?
@rodrickedwards2759
@rodrickedwards2759 4 жыл бұрын
O(N) - N is number of elements the matrix
@laurawu5146
@laurawu5146 4 жыл бұрын
Feel much better to solve problems while watching your video
@li-xuanhong3698
@li-xuanhong3698 3 жыл бұрын
Awesome explanation ! Thanks
@TheMsnitish
@TheMsnitish 5 жыл бұрын
It would be nice if you can post the solution in Github.
@epp5179
@epp5179 Жыл бұрын
Great video! Thank you so much!!!
@Zetta_11
@Zetta_11 2 жыл бұрын
So cool idea! Thank you a lot for your efforts!!!
@Jackson_Leung
@Jackson_Leung 4 жыл бұрын
Great solution! Very intuitive.
@rahulkhatoliya6814
@rahulkhatoliya6814 3 жыл бұрын
Great Explanation ! dude
@dhruva1221
@dhruva1221 5 жыл бұрын
better than that in geeksforgeeks(where I had left comment to use self descriptive var names would do well) which was better than that of code school where I disliked the logic & var names
@dineshkumar-kw1ik
@dineshkumar-kw1ik 2 жыл бұрын
Can anyone, please explain the time complexity for this algorithm?
@sauravbharti2709
@sauravbharti2709 3 жыл бұрын
That was very understandable.. Thank you
@guntukaramakrishna
@guntukaramakrishna 4 жыл бұрын
oh my god.. I am just typing the code continuously after his explanation. It was a nightmare before watching this video. +1 for variable naming. That simply made to write flaw less code.
@surajtopal9940
@surajtopal9940 3 жыл бұрын
woooow, it is very simple using boundaries
@ryfarley
@ryfarley 3 жыл бұрын
Thanks for this. Also, +1 on chocolate covered almond things.
@Shishiraithal
@Shishiraithal 4 жыл бұрын
Best explaination..thanx man
@anirbansarkar6306
@anirbansarkar6306 3 жыл бұрын
awesome solution
@HR-pz7ts
@HR-pz7ts Жыл бұрын
Thanks
@HR-pz7ts
@HR-pz7ts Жыл бұрын
I came back to thank you again orignally I was looking for a solution for spiral matrix 2 and your explanation was so good that I solved a different question with the help of your explanation in this video.
@alammahtab08
@alammahtab08 5 жыл бұрын
If you don't want to type the code, you can get it from here github.com/eMahtab/spiral-matrix
@yij9010
@yij9010 4 жыл бұрын
love it!
@大盗江南
@大盗江南 5 жыл бұрын
Gooooood!
@nileshkhimani9315
@nileshkhimani9315 4 жыл бұрын
hwo to treaverse this spiral matrix in O(logn) time?
@arunshinde6487
@arunshinde6487 3 жыл бұрын
A similar and better solution class Solution { public List spiralOrder(int[][] matrix) { List res = new ArrayList(); if(matrix.length == 0 || matrix[0].length == 0) return res; int top = 0; int bottom = matrix.length-1; int left = 0; int right = matrix[0].length-1; while(true){ for(int i = left; i right || top > bottom) break; for(int i = top; i right || top > bottom) break; for(int i = right; i >= left; i--) res.add(matrix[bottom][i]); bottom--; if(left > right || top > bottom) break; for(int i = bottom; i >= top; i--) res.add(matrix[i][left]); left++; if(left > right || top > bottom) break; } return res; } }
@nileshkhimani9315
@nileshkhimani9315 4 жыл бұрын
please give a solution in O(logn) time please please
LeetCode Search A 2D Matrix Solution Explained - Java
11:47
Nick White
Рет қаралды 39 М.
LeetCode Spiral Matrix II Solution Explained - Java
8:33
Nick White
Рет қаралды 14 М.
UFC 310 : Рахмонов VS Мачадо Гэрри
05:00
Setanta Sports UFC
Рет қаралды 1,2 МЛН
To Brawl AND BEYOND!
00:51
Brawl Stars
Рет қаралды 17 МЛН
Мен атып көрмегенмін ! | Qalam | 5 серия
25:41
СИНИЙ ИНЕЙ УЖЕ ВЫШЕЛ!❄️
01:01
DO$HIK
Рет қаралды 3,3 МЛН
LeetCode 146. LRU Cache (Algorithm Explained)
18:00
Nick White
Рет қаралды 120 М.
I Got Rejected (again)
9:43
Nick White
Рет қаралды 206 М.
LeetCode 5.  Longest Palindromic Substring (Algorithm Explained)
14:40
LeetCode 48. Rotate Image (Solution Explained)
10:18
Nick White
Рет қаралды 86 М.
Self Taught Programmers... Listen Up.
11:21
Nick White
Рет қаралды 1,1 МЛН
The Dome Paradox: A Loophole in Newton's Laws
22:59
Up and Atom
Рет қаралды 1,1 МЛН
LeetCode 442. Find All Duplicates in an Array (Solution Explained)
12:37
How I'd learn ML in 2025 (if I could start over)
16:24
Boris Meinardus
Рет қаралды 19 М.
UFC 310 : Рахмонов VS Мачадо Гэрри
05:00
Setanta Sports UFC
Рет қаралды 1,2 МЛН