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.
Me to me after going through 15:52: that’s cool, let’s settle for the FIRST OPTIMAL SOLUTION.
the way you explained second approach seems a piece of cake now. Thank you very much🙌
really?.... i'm so dumb then
Solved it!!
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
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
Solution 1: 😀
Solution 2: 💀
implementing the brute force approach gives
0ms Beats 100.00% in java wow
😂😂
simpler optimization is calc prefix sum of rows and cols then check sub matrix is 45 if yes run check for magic square
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?
Got a similar brute force Approach but nice explaination!
Second solution is just crazy 🤯🤯
🎉🎉 Nice one
this problem sucks
Why? It's easiest problem.
I liked the math solution, hard to think about it but it's pretty nice
we were challenged by this problem when we were a kid
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...
Is the possible equal sum always 15? How can we arrive at that conclusion? Please Help...
today I got my first "beats 100%" with a runtime of 25 ms without watching this video!!
why do the rows cols and diag sum up to 15?
That math solution is pretty nice, but hard to come up with.
Can anyone tell which tool neet uses for drawing explanation?
can u tell whee is it written that sum should be 15
i lost it when you started rotating and flipping the matrix xd (i am losing it)
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
do u have any coupon code for lifetime acess pls
i'm gonna settle with the first solution
Raise your hands if your brain got rotated at 19:00 😂🙋♂️
first time i'm the first viewer PogChamp