What most developers mean that it is relatively easy. Like it is relatively easy to get a phd than to become President. Both are exceptionally hard to get though.
Huh, the advantages of knowing your data structures and methods...I've spent 10+ hours on a similar sudoku problem and been trying to use only arrays and 2d arrays combined with control statements, and it's been a nightmare to be honest, and now I see this and I really think I gotta learn some data structures, it's ridiculous how fast you can come up a solution like this
If you feel bad...don't. He spends a lot of time beforehand looking at different solutions, trying to come up with his own solutions, improve it and improving the different solutions he saw. And then, choosing the best one. This is pure hardwork.
This is lit. No words. I solved the arcade section of the sudoku by using two hashset one for row and one for column. Never thought this could be the way to optimise the code.
This was a really cool solution Sir, so we can also implement even a string matching algo using string datatype hash set. This problem really teaches a cool concept!! Thank You Sir!!
You could also make a list of 81 list with 9 entries each for every field and number that is possible. Then you write a algorithm that cross out each number from the nine possibilieties that has a double in line, colum or quadrat. When all numbers cut one in a list are crossed out, you have found a new one that you can use to delete the other list of posibilities. If each list have just a number its solved!
A clever solution, but the simple solution (Validating rows, columns, and boxes seperately) is way more faster, for me this solution beat 100% of java solution in term of time, the solution in the video beat 22% only (Which is because of strings hashing I guess).
Also, you could remove the big 'if' from the 'for' loop and just check if the size of the set is 3*(Number of non-empty places in the board) after the loop. If it is not, the answer is false.
The string concatenation allows using only one map, but what is the point of this? It's nifty, but I don't see a real reason to use this from a practical standpoint
I tried doing the nested if with normal (seen.add) instead of (!seen.add), return true and return false in outside the for loops. but that doesn't work. Can you tell why?
Wouldn't this fail if one of the 3x3 squares looks like 1 2 3 4 5 6 7 8 9 and if there is another 3x3 square to the left or the right of the first 3x3 square that looks like 7 4 5 8 2 3 6 1 x where the x denotes an empty square, then this is an unsolvable Sudoku puzzle.
does same number of elements in one hash Set or 3 hash set make a difference on memory usage? after all same units of memory is being allocated but pointers to each memory changes right? the type is same (char)
Leetcode's system of calculating this is flawed.. I have seen same thing submission showing up as faster than (12%-80%) and then back to 12% within a minute.. (network connection or something)
Because this solution is really bad for performance. It's a nice quick solution in a coding interview, but if you want fast execution times, you shouldn't even think about generating strings to hash them... It should more look like this: public boolean isValidSudoku(char[][] board) { for(int i=0; i
@@sudhanshushakya4579 ya that will be work fine for rows use ur unordered_sename[i].(arr[i][j]and column use ur unordered set name[j].find(arr[i][j]) and array element arr[i][j] and for boads use following as it is 9^9 matrix use arr[i]j].find(arr[i][j]*3(i/3)*(j/3))
at 9:08 when he said it is not difficult, my face turned into red. If I've never saw this kind of solution before, I would be doomed in a interview :)
lol he says that for so many problems and I get kinda sad when I hear that :(
@@Kitchen-Raccoon4572 Don't get sad... Nick is a little arrogant plus he has been doing this for a while. Practice makes perfect!
What most developers mean that it is relatively easy. Like it is relatively easy to get a phd than to become President. Both are exceptionally hard to get though.
For real!!!!!
Sheesh I spend 2 hours just to figure out what is happening in my code!!
The solution with the single string HashSet looks like pure genius to me.
Great video!
big brain solution
This honestly was the simplest and best solution i've seen.
Readable code is much better than smart code. Your solution is understandable. Thanks.
Huh, the advantages of knowing your data structures and methods...I've spent 10+ hours on a similar sudoku problem and been trying to use only arrays and 2d arrays combined with control statements, and it's been a nightmare to be honest, and now I see this and I really think I gotta learn some data structures, it's ridiculous how fast you can come up a solution like this
If you feel bad...don't. He spends a lot of time beforehand looking at different solutions, trying to come up with his own solutions, improve it and improving the different solutions he saw. And then, choosing the best one.
This is pure hardwork.
This is lit. No words. I solved the arcade section of the sudoku by using two hashset one for row and one for column. Never thought this could be the way to optimise the code.
One word - Genius
The answer were already on leet code. 😅
bro you have the best explanation that i've seen. Thank you so much
This was a really cool solution Sir, so we can also implement even a string matching algo using string datatype hash set. This problem really teaches a cool concept!! Thank You Sir!!
That moment when he first type the input for strings hash set is just simply mind blowing like "OMG off course it will works"
It will work better than your grammar teacher.
@@Last_Resort991 when the grammar nazi doesn't know grammar himself lol
Exploded my mind what a brilliant way to write aesthetic code man !!
Wow! This is the most intuitive solution I've seen to this problem
Great Solution!!
Thank Nick for posting these videoss
You could also make a list of 81 list with 9 entries each for every field and number that is possible. Then you write a algorithm that cross out each number from the nine possibilieties that has a double in line, colum or quadrat. When all numbers cut one in a list are crossed out, you have found a new one that you can use to delete the other list of posibilities. If each list have just a number its solved!
This trick is INSANE!!!! I hope I never get asked a problem like this lol
Brilliant!! Just to make sure, is the time and space O(1)?
Curios if it is possible to extend this solution to solve the Sudoku solver problem...
WOW amazing solution loved it keep it up dude!
Trivia : Nick White still has the hat used in his profile picture, and actually went to Columbia
A clever solution, but the simple solution (Validating rows, columns, and boxes seperately) is way more faster, for me this solution beat 100% of java solution in term of time, the solution in the video beat 22% only (Which is because of strings hashing I guess).
Also, you could remove the big 'if' from the 'for' loop and just check if the size of the set is 3*(Number of non-empty places in the board) after the loop. If it is not, the answer is false.
This was a very different approach !
Rather than using 3 hashsets using a single hashset was brilliant .
Wow, what a smart solution bruh !
Really good explanation, thx mate!
your vids are really helpful THANKS A LOAD
What is the runtime for your solution? Is it O(n^2)?
Yes.
It is O(1). The for loop will always run for 9x9 grid irrespective of input if thats how you came up with O(n).
@wapanapoli How can the grid size change lol please explain
@@praharsh_bhatt The grid is always 9x9 (even says in the video), so the time complexity is O(1)
Loved the solution!
wow..that blew my mind...I mean wow...
Im speechless
Can anyone give the cpp solution of this question,I am having some issues in my code.Thanks in advance:)
wow Awesome, and I was spending hours to just solve this
The string concatenation allows using only one map, but what is the point of this? It's nifty, but I don't see a real reason to use this from a practical standpoint
This is an awesomeeeeeee solution. I am mesmerized!!!! :)
I tried doing the nested if with normal (seen.add) instead of (!seen.add), return true and return false in outside the for loops. but that doesn't work. Can you tell why?
in nested if statement you forgot to put ! symbol to check it..
its showing unexpected return value for return false line... wat to do
WoW! That's so freaking cool..
Brilliant solutions :D
this method is fucking genius
genious, thank you very much
Wouldn't this fail if one of the 3x3 squares looks like
1 2 3
4 5 6
7 8 9
and if there is another 3x3 square to the left or the right of the first 3x3 square that looks like
7 4 5
8 2 3
6 1 x
where the x denotes an empty square, then this is an unsolvable Sudoku puzzle.
It's doesn't matter if the sudoku puzzle is unsolvable. This leetcode problem is only checking for the three rules in the description
does same number of elements in one hash Set or 3 hash set make a difference on memory usage? after all same units of memory is being allocated but pointers to each memory changes right? the type is same (char)
Well yea, you're using more memory
Yeah, even I had the same question.
Thanks for explaining. What's the time complexity?
O(n*n) where n is the size of the board
I'm not understanding the logic and code for specifying a cube. It makes no sense to me.
It's a 9x9 grid. A box is 3x3. If you divide the index of a row and column by 3, you get the box you're currently in.
Me: (video put on mute until he claps)
nice explanation
It was a nice AHAAAAAAA moment =D Thank you!
really helpful thanks :3
Great job
Thank you so much
F R E A K I N G GeniusSSSSSSSSSSS!! :D Mind=blown :)
This is beautiful
StefanPochmann sends regards ;)
LOL if we used three iterations instead of 1 iteration it will return 95% more faster solutions,in case of 1 iteration in c++ 35% only
Really? Snake_case in java? 😅 Anyway, cool content bro
I did this in c++ and got only 6% faster. You also only got 22% This solution is a joke.
Leetcode's system of calculating this is flawed.. I have seen same thing submission showing up as faster than (12%-80%) and then back to 12% within a minute.. (network connection or something)
Hye, can you show me your cpp implementation? I am having trouble doing it.
I used unordered_set in place of HashSet.
Because this solution is really bad for performance. It's a nice quick solution in a coding interview, but if you want fast execution times, you shouldn't even think about generating strings to hash them...
It should more look like this:
public boolean isValidSudoku(char[][] board) {
for(int i=0; i
@@sudhanshushakya4579 ya that will be work fine for rows use ur unordered_sename[i].(arr[i][j]and column use ur unordered set name[j].find(arr[i][j]) and array element arr[i][j] and for boads use following as it is 9^9 matrix use arr[i]j].find(arr[i][j]*3(i/3)*(j/3))
WTF mannnnnnn...........................Destroyed it like a proooooo
Nick no filter white
You look like sheldon
looks like you hate to use camelCase in the camelCase world of Java. :D
He codes in JS except for Data Structures I think thats where the underscores come from ;)
Mind boggling🔥
brilliant !!!!
excellent !!!!
this makes me look dumb
Clever as fuck
This algorithm is wrong as it only check for first subset not all 9 subsets.
worst explanation ever!! no intuition or walk through whats so ever cannot explain this in an interview!
Genius
Explanation according to discussion, no details. Not worth to go through.
I hope you don't get tired of my comments but this is ridiculous(in a good way )
nice.
get it
we dont know what u mean ,
WTF
Review
wow :)
18
:-) !!! awesome!!!!!
Champ!
This does not work. Waste of time