Spiral Matrix III - Leetcode 885 - Python

preview_player
Показать описание


0:00 - Read the problem
0:30 - Drawing Explanation
4:49 - Coding Explanation

leetcode 885

#neetcode #leetcode #python
Рекомендации по теме
Комментарии
Автор

Always struggled with matrix traversing. Your explanation makes it looks simple and easier. Thanks for adding this one.

ArunRampure
Автор

Thanks for mentioning the pattern at 2:40 so that we could try it ourselves!

lavanya_m
Автор

I solved this problem the way like you solved Sprial Matrix (the first one). I defined top, bottom, left and right boundaries and traversed right bottom left and top until I hit boundaries. While traversing if current row and col is in between 0 and len(row or col) I added it to result.

MehmetDemir-xiyy
Автор

Kinda diff one today. Yesterday 'hard' problem was much more easier. Thanks for explanation, NeetCode, love u!

АльбусДамблодр
Автор

You write these codes so elegantly and efficiently!
I love how you implement things like e.g. the part where you used the loop and then increased the steps counter, making us realize how to creatively use loops .

Thanks for putting out a video for daily leetcode, because of you I'm able understand and implement and making small and consistent efforts to do DSA daily.

rahulsbhatt
Автор

I usually get the logic for most leetcode problems, but your solutions are far more elegant than mine. Your code looks like an artwork, while mine look like a 3 year old's drawing

pss
Автор

I was sooo confused on this problem, mainly because I thought the arrow was showing me where it stops but I took that too deep lol. Thank you for explaining this to me :)

lifeofaproblemsolver
Автор

Unrelated to this question, just wanna say thank you neetcode for your videos on LC and general topics, you are amazing and a great inspiration 🙏🙏

bob-the-constructors
Автор

Solved it by counting steps out load, 1, 1, 2, 2, 3, 3 etc made me figure it out. :)

Vancha
Автор

Everyday I watch your videos and learn something. Thank you very much.

OmarAlimammadzade-vs
Автор

Great explanation as always. Thank you

MP-nyep
Автор

I took the approach that each of these directions move out diagonally. So incremented them diagonally

rev_krakken
Автор

I didn't get y u r doing y in range(steps) ?? N how u r covering at a certain distance from the origin coordinate??
Or r you doing it through steps only ??

rajshah
Автор

The intern writers are definitely paid a competitive wage to write this.

yang
Автор

Today I feel accoplished because my code is an exact match for NeetCode's.

res = [[rStart, cStart]]
deltas = [(0, 1), (1, 0), (0, -1), (-1, 0)]
d, incDist = 0, 1

while len(res) < rows * cols:
for _ in range(2):
for _ in range(incDist):
rDelta, cDelta = deltas[d]
rStart, cStart = rStart + rDelta, cStart + cDelta
if 0 <= rStart < rows and 0 <= cStart < cols:
res.append([rStart, cStart])
d = (d + 1) % 4
incDist += 1

return res

omkarnag
Автор

Does amyone else love diving into ASM, C and C++ before going back up to Java, C#, Python Java... JavaScript?

gurbanaarongulman
Автор

I made a 100 lines solution then I came here

EduarteBDO
Автор

spiral matrix 4 is gonna be the end of my sanity fs

pastori
Автор

i got brain damage yesterday for this problem

ctj
Автор

Who woke up early to solve the daily question on leetcode everyday 😌??

ROHANMANNA-ilnt