That second solution is awesome. Idk, I get excited seeing math solutions with these logic tricks. It's like finding a trap door. If this wasn't for leetcode, i'd be feeling more positively about this
Got the intuition and did a slightly different solution, did a few optimizations (with less readability) in the isMagic method def numMagicSquaresInside(self, grid: List[List[int]]) -> int: if len(grid) < 3 or len(grid[0]) < 3: return 0 def isMagic(r, c): cols = [0 for _ in range(3)] rows = [0 for _ in range(3)] diags = [0 for _ in range(2)] seen = set() for i in range(r, r+3): for j in range(c, c+3): if grid[i][j] in seen or not (1
In the second solution, won't it fail on a grid that follows the rotational pattern but puts the odds in the corners and evens in the edges? Should there also be a second condition on pattern checking that makes sure [r-1][c] is odd?
I think the problem itself is easy enough if you stick to the first solution. A bit tedious but definitely much better than that Integer to English one...
You didn't think the Leetcode problems could get worse, yet here we are.
this week is just the worst problems week, there's no category, and leetcode knows it
Didn't feel like doing this problem, but streak :(
same
That second solution is awesome. Idk, I get excited seeing math solutions with these logic tricks. It's like finding a trap door. If this wasn't for leetcode, i'd be feeling more positively about this
Thank you so much for the daily leetcode.
Solved it!!
the way you explained second approach seems a piece of cake now. Thank you very much🙌
really?.... i'm so dumb then
Got the intuition and did a slightly different solution, did a few optimizations (with less readability) in the isMagic method
def numMagicSquaresInside(self, grid: List[List[int]]) -> int:
if len(grid) < 3 or len(grid[0]) < 3:
return 0
def isMagic(r, c):
cols = [0 for _ in range(3)]
rows = [0 for _ in range(3)]
diags = [0 for _ in range(2)]
seen = set()
for i in range(r, r+3):
for j in range(c, c+3):
if grid[i][j] in seen or not (1
Me to me after going through 15:52: that’s cool, let’s settle for the FIRST OPTIMAL SOLUTION.
Thanks for the explanation! But I don't think the question mentioned that the sum of each row/col/diag is 15.
Aw I forgot to explain that part, since sum(1..9) = 45, and each row has to have the same sum, it must be 15. Same for columns and diagonals
@@NeetCodeIO nice observation
Solution 1: 😀
Solution 2: 💀
Got a similar brute force Approach but nice explaination!
In the second solution, won't it fail on a grid that follows the rotational pattern but puts the odds in the corners and evens in the edges? Should there also be a second condition on pattern checking that makes sure [r-1][c] is odd?
Second solution is just crazy 🤯🤯
this problem sucks
Why? It's easiest problem.
🎉🎉 Nice one
why do the rows cols and diag sum up to 15?
implementing the brute force approach gives
0ms Beats 100.00% in java wow
😂😂
can u tell whee is it written that sum should be 15
simpler optimization is calc prefix sum of rows and cols then check sub matrix is 45 if yes run check for magic square
I liked the math solution, hard to think about it but it's pretty nice
Is the possible equal sum always 15? How can we arrive at that conclusion? Please Help...
we were challenged by this problem when we were a kid
That math solution is pretty nice, but hard to come up with.
Can anyone tell which tool neet uses for drawing explanation?
do u have any coupon code for lifetime acess pls
Raise your hands if your brain got rotated at 19:00 😂🙋♂️
two 20+ min solution vids in one week. god help us
Yeah aren't the problems supposed to be easy at the beginning of the month
I think the problem itself is easy enough if you stick to the first solution.
A bit tedious but definitely much better than that Integer to English one...
i lost it when you started rotating and flipping the matrix xd (i am losing it)
today I got my first "beats 100%" with a runtime of 25 ms without watching this video!!
Why you took 1 first instead of 2,3,4,5,6,7,8,9 and then made patterns on 14 ?
Just to go through them in order, it's arbitrary but easier to keep track of starting at 1.
We want them to sum to 15, hence 15 - 1 = 14
i'm gonna settle with the first solution
first time i'm the first viewer PogChamp