Two is easier than one because it’s easy to forget to recheck the left / right and top / bottom conditions half way through the main loop due to rectangular cases
does this code work for, I am getting an error "IndexError: list assignment index out of range" Can you explain what is happening "class Solution: def generateMatrix(self, n: int) -> List[List[int]]: mat = [[0] *n for _ in range(n)] left, right = 0, n - 1 top, bottom = 0, n - 1 val = 1 while left
We can use a circular linked list of pairs with the directions like this (1,0), (0,1), (-1,0), (0, -1) each time the value we are at satisfies this value - 1% N-1 == 0 we advance our list add the pair to row and col values, value++ and terminate the loop when value == n^2, instead of 4 pointers we have a list of 4 direction pairs, the reminder operation left hand side will decrease by 1 each 3 direction changes
@@NeetCodeIO class Solution: def generateMatrix(self, n: int) -> List[List[int]]: mat = [[0] *n for _ in range(n)] left, right = 0, n - 1 top, bottom = 0, n - 1 val = 1 while left
@@sanjeevmurmu6505 after your middle 2 for loops youre doing right = 1 and bottom = 1 instead of decrementing them: right -= 1 and bottom -=1. Just missing the - signs.
Two is easier than one because it’s easy to forget to recheck the left / right and top / bottom conditions half way through the main loop due to rectangular cases
does this code work for, I am getting an error "IndexError: list assignment index out of range" Can you explain what is happening
"class Solution:
def generateMatrix(self, n: int) -> List[List[int]]:
mat = [[0] *n for _ in range(n)]
left, right = 0, n - 1
top, bottom = 0, n - 1
val = 1
while left
@@sanjeevmurmu6505 right -=1 and bottom -= 1 should be there, "-"(minus) is missing
We can use a circular linked list of pairs with the directions like this (1,0), (0,1), (-1,0), (0, -1) each time the value we are at satisfies this value - 1% N-1 == 0 we advance our list add the pair to row and col values, value++ and terminate the loop when value == n^2, instead of 4 pointers we have a list of 4 direction pairs, the reminder operation left hand side will decrease by 1 each 3 direction changes
Thank you for the daily leetcode problems.
Sweeeet. Loving these videos.
best explain, thanks
good solution bro
Thank you so much
does this code work for anybody here, I am getting an error "IndexError: list assignment index out of range" Can anybody explain what is happening
It's most likely a typo in your code. Hard to debug without seeing it.
@@NeetCodeIO
class Solution:
def generateMatrix(self, n: int) -> List[List[int]]:
mat = [[0] *n for _ in range(n)]
left, right = 0, n - 1
top, bottom = 0, n - 1
val = 1
while left
@@sanjeevmurmu6505 after your middle 2 for loops youre doing right = 1 and bottom = 1 instead of decrementing them: right -= 1 and bottom -=1. Just missing the - signs.
@@sanjeevmurmu6505 while left
Hey man I am poor can you give me advice
dont be poor