L15. Sudoko Solver | Backtracking

  Рет қаралды 246,855

take U forward

take U forward

3 жыл бұрын

Check our Website:
In case you are thinking to buy courses, please check below:
Link to get 20% additional Discount at Coding Ninjas: bit.ly/3wE5aHx
Code "takeuforward" for 15% off at GFG: practice.geeksforgeeks.org/co...
Code "takeuforward" for 20% off on sys-design: get.interviewready.io?_aff=takeuforward
Crypto, I use the Wazirx app: wazirx.com/invite/xexnpc4u
Take 750 rs free Amazon Stock from me: indmoney.onelink.me/RmHC/idje...
Earn 100 rs by making a Grow Account for investing: app.groww.in/v3cO/8hu879t0
Linkedin/Instagram/Telegram: linktr.ee/takeUforward
---------------------------------------------------------------------------------------------------------------------------------------------------- Pre-Requisites: Recursion Playlist Videos,
✅Coding Ninjas Discount Link: aff.codingninjas.com/click?o=...
Please Please SUBSKRIIIBEEEEE the new channel: / @striver_79
Problem Link: leetcode.com/problems/sudoku-...
C++/Java Code Efficient: takeuforward.org/data-structu...
---------------------------------------------------------------------------------------------------------------------------
✅This is where I teach: ----- Use coupon-code "TAKEUFORWARD" for getting 10% on my course at GFG: bit.ly/striver_cpCourse​
✅Use coupon-code "TAKEUFORWARD" for getting 10% for all GFG courses: bit.ly/tuf_gfgCourse​
---------------------------------------------------------------------------------------------------------------------------
If you appreciate the channel's work, you can join the family: bit.ly/joinFamily​
✅Thumbnail Creator: / rikonakhuli
✅ Striver's Linkedin Profile: / ​
✅ Instagram: / ​
✅Connect with us: bit.ly/tuftelegram​ (Use Link in Mobile only, if not works search "takeUforward" in telegram)..
#dsa​ #striver #placements

Пікірлер: 313
@takeUforward
@takeUforward 3 жыл бұрын
Instagram for live updates about channel and live sessions: striver_79
@prithvijitbasak
@prithvijitbasak 3 жыл бұрын
Bhaiya you are just a mastermind not only by your skills but you know the every bit of doubts that arise in a student's mind. Hats off to your explanation skills. 🔥🔥🔥❤️
@pranavgawade1546
@pranavgawade1546 3 жыл бұрын
Wo sare sudoku boards bharte bharte dimag kharab ho gaya hoga XD
@democratcobra
@democratcobra 2 жыл бұрын
You are doing one revolutionary work. Word will change and remember your contribution.
@parthsalat
@parthsalat 2 жыл бұрын
@@democratcobra Er....Which *word* will change?
@aeroabrar_31
@aeroabrar_31 Жыл бұрын
Lol ! Am i the only one who learnt sudoku games just to solve this problem. 😂
@bhargav1811
@bhargav1811 Жыл бұрын
Those who can't understand the logic for subgrid part of sudoku can think of like - There are 3 sized rows and columns so we have to do row/3 and column/3 to get what specific subgrid we are in !!! But this will not be enough as we have to traverse whole subgrid also, so we have to add various coordinates like - offset is nothing but first element of subgrid offset(which we can get by row//3 and col//3) + for each of given below (0,0) (0,1),(0,2), (1,0) (1,1),(1,2), (2,0) (2,1),(2,2) offset + (0,0) offset + (0,1) offset + (0,2) offset + (1,0) offset + (1,1) offset + (1,2) offset + (2,0) offset + (2,1) offset + (2,2) For example if we talk about what striver talks about at 19:24 (5,7) position we can get subgrid offset by row offset = 5//3 ==>1 col offset = 7//3 ==> 2 which is second rowth and third column subgrid - | 0,0 | 0,1 | 0,2 | | 1,0 | 1,1 | 1,2 | | 2,0 | 2,1 | 2,2 | The above is all 9 subgrid of sudoku Again back with example we get 1,2 grid and now we have to add all coordinates to traverse that block like (0,0) (0,1),(0,2), (1,0) (1,1),(1,2), (2,0) (2,1),(2,2) for x= 0,0,0,1,1,1,2,2,2 ( extracting all x of above ) for y = 0,1,2,0,1,2,0,1,2 (extracting all y of above ) so basically x = i//3 and y = i%3 for i ranging from 0 to 9 so finally formula is for i=0 to 9- row = 3 * (x//3) + i//3 ==> (offset + 0,0,0,1,1,1,2,2,2 ) col = 3*(y//3) + i % 3 ==> (offset + 0,1,2,0,1,2,0,1,2 )
@ankitpradhan2499
@ankitpradhan2499 Ай бұрын
from where can i get the same deciphering technique ?? some resources ?
@swordofgrayskull1530
@swordofgrayskull1530 3 жыл бұрын
Hey King take this 👑, it belongs to you now.
@satyamsrivastava.
@satyamsrivastava. 3 жыл бұрын
I heard u many times saying u r bad at drawing bt this suduko board is literally very artistic
@studyonline3236
@studyonline3236 Жыл бұрын
My suggestion would be to pass on the row number along with the board to solve function, because say you're calling solve(board) [recent insertion done at 6,7], the function again starts from the start(0) row to find an empty cell, but if you'd passed solve(board,row=6) the search starts from the same row as you're sure that there wouldn't be any free cells left in prior rows.
@akku5529
@akku5529 Жыл бұрын
Yes definitely, It will save the iteration of the rows where values are already set. Now you just need to switch to the next row for which you will simply increment the value of row in the function call. I have applied this method, Below the python Implementation of the problem: class Solution: def isValid(self,board,row,col,val): for i in range(9): if (board[row][i] == val): return False if (board[i][col] == val): return False if(board[3*(row//3)+(i//3)][3*(col//3)+(i%3)] == val): return False return True def solve(self,board,row): if (row == 9):return True for col in range(9): if(board[row][col] == '.'): for val in map(str,range(1,10)): if self.isValid(board,row,col,val): board[row][col] = val if self.solve(board,row): return True else: board[row][col] = "." return False return self.solve(board,row+1) def solveSudoku(self, board: List[List[str]]) -> None: """ Do not return anything, modify board in-place instead. """ self.solve(board,0)
@sudhirdharmadhikari1938
@sudhirdharmadhikari1938 Жыл бұрын
Very true. That is an important point
@chirags2711
@chirags2711 Жыл бұрын
It would have mattered more if number of rows/columns was huge. In this question, we only have to do it for 9, so won't really make more than a very very slight difference at all.
@parthhh3589
@parthhh3589 8 ай бұрын
yes@@chirags2711
@Abhishek-yy3xg
@Abhishek-yy3xg 3 жыл бұрын
Yesterday I was trying to understand Sudoku for this problem. And here you come with perfect explanation. Thank you 🙂
@freshcontent3729
@freshcontent3729 3 жыл бұрын
what is the TC for this ques ? please explain , please help me , thanks..
@TonyStark-ct8xd
@TonyStark-ct8xd 2 жыл бұрын
@@freshcontent3729 for each empty box, we have 9 choices (1-9), therefore maximum tc is 9^N*N, where N is dimension of grid.
@sanketatmaram
@sanketatmaram Жыл бұрын
Best Explanation and consistent logic over all recursion backtracking question in the series. Great work
@shastriamisha
@shastriamisha 2 жыл бұрын
The best explanation on YT for this problem. I can never forget the logic ever :) Thank you
@shiwamsinha7076
@shiwamsinha7076 2 жыл бұрын
thanks a lot, sir for boosting my confidence that i can do programming by just applying common sense
@RonitChattopadhyay
@RonitChattopadhyay 3 жыл бұрын
Appreciate the effort that you have put to explain this problem.
@TheAditya-zt9pb
@TheAditya-zt9pb Ай бұрын
I was initially stucked at the place where we have to check whether the sub-matrix is filled from 1-9 or not but the way you have explained it by diving the rows and colums by 3 and adding them to check the all the numbers made me Mind blown ..this is the far best Explanation ,loved it
@kirannagulakonda3443
@kirannagulakonda3443 Жыл бұрын
Really appreciate your efforts brother, took time but really happy to solve the question just by watching intuition.
@shaleen9434
@shaleen9434 Жыл бұрын
I am getting this error when i am submitting my soln in leetcode can anyone please help? AddressSanitizer:DEADLYSIGNAL ================================================================= ==30==ERROR: AddressSanitizer: stack-overflow on address 0x7ffef164fff8 (pc 0x000000345d18 bp 0x7ffef1650010 sp 0x7ffef1650000 T0) ==30==ABORTING
@ayanSaha13291
@ayanSaha13291 2 ай бұрын
bro, I salute your patience! I never have seen such an explanation for the problem! Thanks a lot.
@suyashmishra6946
@suyashmishra6946 Жыл бұрын
Hella understood man. Ig the most tricky part of this question was to check for 3*3 matrix, that you explained really well.
@sunnykumarpal9679
@sunnykumarpal9679 Жыл бұрын
Bhaiya before I was feeling recursion a tough topic but seeing your video now i am enjoying doing recursion thanks lot bahiya for providing such contents.
@zaidmujahid3885
@zaidmujahid3885 2 жыл бұрын
Best explanation for sudoku solver on KZbin 💯
@nitunsingh6986
@nitunsingh6986 2 жыл бұрын
Superb Explanation Bhaiya . I know how much efforts u put to come with a beautiful content .Hats off for u
@kashishshukla23
@kashishshukla23 2 жыл бұрын
Great explanation!! Really appreciate your efforts
@unibrow9384
@unibrow9384 2 жыл бұрын
Thanks a lot, haven't seen anyone explain so well and in such detail ! ^_^
@SahilSharma-vl9rk
@SahilSharma-vl9rk 2 жыл бұрын
Woah thanks for this bro :) I literally never understood this problem and finally after watching your video I understood it completely.
@samsmith3961
@samsmith3961 Жыл бұрын
the shear amount of effort that must have gone while making this video is certainly commendable... some of the best DSA channel for a reason... gg @takeUforward
@AryanSharma-dc4bj
@AryanSharma-dc4bj Жыл бұрын
exactlyy
@cinime
@cinime Жыл бұрын
Understood! Super amazing explanation as always, thank you very much!!
@kritikatyagi4325
@kritikatyagi4325 Жыл бұрын
What a simple solution to such a complex problem hats off to u sir
@kalidass6531
@kalidass6531 3 жыл бұрын
Thank you for this wonderful explanation!.
@Tomharry910
@Tomharry910 Жыл бұрын
Brilliant explaination. Great video. Thank you!
@preetamkumar838
@preetamkumar838 2 жыл бұрын
N queens problem and sudoku solve were not as easy as it seems now after going through your videos. Best thing I have found on KZbin. Thanks a lot for making such complex things easier to understand.
@prathamsagar5353
@prathamsagar5353 Жыл бұрын
You are a true king in explaining logic!
@ashdeepsingh6785
@ashdeepsingh6785 2 жыл бұрын
Understood the concept. Thanks for putting this much effort.
@nareshe2383
@nareshe2383 2 жыл бұрын
Great work, We can also solve this problem with out nested loops by passing row number as parameters to reduce the complexity.
@ka_ka3141
@ka_ka3141 2 жыл бұрын
No for iterations it's not possible
@nasim3987
@nasim3987 4 ай бұрын
@@ka_ka3141it is possible python code:class Solution: def isValid(self,k,r,c,board): for i in range(9): if board[i][c]==k: return False if board[r][i]==k: return False if board[3*(r//3)+i//3][3*(c//3)+i%3]==k: return False return True def func(self,board,r): for i in range(r,9): for j in range(9): if board[i][j]=='.': for k in "123456789": if self.isValid(k,i,j,board): board[i][j]=k if self.func(board,i): return True else: board[i][j]='.' return False return True def solveSudoku(self, board: List[List[str]]) -> None: self.func(board,0)
@trooperzooper6092
@trooperzooper6092 10 ай бұрын
Like I've seen Some other videos of Sudoku solver, and they all just used that formula, and said you can use this, but striver you really helped me understand the formula, And I just wanted to say Thank you!
@studynewthings1727
@studynewthings1727 9 ай бұрын
I understood very well, Thankyou for good explanation.
@parambharti7095
@parambharti7095 Жыл бұрын
Great effort. Very informative. Thanks @Striver.
@amanbhadani8840
@amanbhadani8840 2 жыл бұрын
Your videos made questions like this too much easier.
@fahmidayasmin4923
@fahmidayasmin4923 27 күн бұрын
The BEST video on this topic in youtube...Thank you!
@stith_pragya
@stith_pragya 2 ай бұрын
UNDERSTOOD.....Thank You So Much for this wonderful video........🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
@yashwantlalwani
@yashwantlalwani Жыл бұрын
amazing, really great explanation.
@itz_me_imraan02
@itz_me_imraan02 2 жыл бұрын
Crystal clear explanation as 🙏
@cartidise
@cartidise 11 ай бұрын
Beautifully explained!
@shrikkanthsuresh8971
@shrikkanthsuresh8971 Жыл бұрын
Into my list of greatest tutors.
@philosphize
@philosphize Жыл бұрын
Thank you so much for the explanation Learnt alot
@user-ot1rd8hd3d
@user-ot1rd8hd3d 7 ай бұрын
The best explanation on YT for this problem
@sanchitakasat
@sanchitakasat 2 жыл бұрын
Amazing explaination!!
@naveentata
@naveentata 2 жыл бұрын
Great explanation!.Thank you. Can you also please make a video on this backtracking leetcode question? "1240. Tiling a Rectangle with the Fewest Squares"
@nopecharon
@nopecharon 2 жыл бұрын
Just a beautiful explanation. You are legend striver
@shaleen9434
@shaleen9434 Жыл бұрын
I am getting this error when i am submitting my soln in leetcode can anyone please help? AddressSanitizer:DEADLYSIGNAL ================================================================= ==30==ERROR: AddressSanitizer: stack-overflow on address 0x7ffef164fff8 (pc 0x000000345d18 bp 0x7ffef1650010 sp 0x7ffef1650000 T0) ==30==ABORTING
@riteshadwani9084
@riteshadwani9084 Жыл бұрын
This guy makes it so easy!
@SuvradipDasPhotographyOfficial
@SuvradipDasPhotographyOfficial Жыл бұрын
Exceptional explanation, Thanks a lot striver
@harshal07051995
@harshal07051995 2 жыл бұрын
Thank you very nicely explained
@akshaymondal1372
@akshaymondal1372 3 жыл бұрын
Bhaiya I just love your videos . I have been following u since many months . Can u make videos about different projects and what should we learn while we work on our Ds algo .
@SamPrakashM
@SamPrakashM 5 ай бұрын
Thank you for the wonderful solution keep doing sir
@chinmaykulkarni8062
@chinmaykulkarni8062 Жыл бұрын
WHT A EXPLANATION !!!! Killed it.....
@sumitmaurya4032
@sumitmaurya4032 2 жыл бұрын
really you made it very simeple.. Thanks for this video
@ritikashishodia675
@ritikashishodia675 2 жыл бұрын
Bhaiya ap great ho..... #below tier3 ki inspiration ho ap.....
@sushantgupta4757
@sushantgupta4757 2 жыл бұрын
thank you so much bhaiya you made so many things in easy way
@mrpi230
@mrpi230 2 жыл бұрын
Great explanation Thank You😀
@shaleen9434
@shaleen9434 Жыл бұрын
I am getting this error when i am submitting my soln in leetcode can anyone please help? AddressSanitizer:DEADLYSIGNAL ================================================================= ==30==ERROR: AddressSanitizer: stack-overflow on address 0x7ffef164fff8 (pc 0x000000345d18 bp 0x7ffef1650010 sp 0x7ffef1650000 T0) ==30==ABORTING
@ronaksiddhpura07
@ronaksiddhpura07 11 ай бұрын
@striver best explaination in easy manner
@jatinkumar4410
@jatinkumar4410 Жыл бұрын
Great explanation as always. Can you please explain its time and space complexity...
@yativishnoi5110
@yativishnoi5110 Жыл бұрын
Well explained!!
@prikshit8
@prikshit8 3 жыл бұрын
thank you so much bhaiya. :)
@AnandBaburajan
@AnandBaburajan 2 жыл бұрын
Thank you!
@thirumalpriyan3528
@thirumalpriyan3528 17 күн бұрын
awesome explanation
@DhruvSharma-mh5vf
@DhruvSharma-mh5vf 2 жыл бұрын
Very well explained sir
@debasishphukon5345
@debasishphukon5345 Жыл бұрын
Great Explanation as always! In the formula to check for the subgrid, I was thinking (3*(row/3) + i/3) can be simplified to (row + i/3), but then i figured we cant do this becuase the (row/3) operation will take the floor value. for e.g. if row = 5 row/3 = 5/3 = 1 so now, 3 * (row/3) = 3 But if we directly take row it will be 5 which is wrong!
@shaleen9434
@shaleen9434 Жыл бұрын
I am getting this error when i am submitting my soln in leetcode can anyone please help? AddressSanitizer:DEADLYSIGNAL ================================================================= ==30==ERROR: AddressSanitizer: stack-overflow on address 0x7ffef164fff8 (pc 0x000000345d18 bp 0x7ffef1650010 sp 0x7ffef1650000 T0) ==30==ABORTING
@mechros4460
@mechros4460 Жыл бұрын
good note. I was thinking about this as well. Thanks for clearing it up.
@yogeshagarwal8537
@yogeshagarwal8537 2 жыл бұрын
If you know how to solve sudoku, you can start from 4:00
@user-fl1km1jq1d
@user-fl1km1jq1d 9 ай бұрын
Awesome explanation
@parthsalat
@parthsalat 25 күн бұрын
Note: We don't need to write "Else". This is because in the if condition, we are anyways "return"ing
@srivastavkumar5497
@srivastavkumar5497 Жыл бұрын
Great explanation
@bhaveshkumar6842
@bhaveshkumar6842 2 жыл бұрын
Striver, I am supremely grateful for your content. You're the best! Btw, a given Sudoku puzzle can have only one valid solution unlike what you said at 12:23. But again this video is great just like all your other videos. You are the best!!! I have immense gratitude for your efforts.
@asutoshghanto3419
@asutoshghanto3419 2 жыл бұрын
no ,it can have many as well but It is a bad puzzle.
@bhaveshkumar6842
@bhaveshkumar6842 2 жыл бұрын
@@asutoshghanto3419 Yes, your point is valid but I was talking about a valid Sudoku puzzle
@shaleen9434
@shaleen9434 Жыл бұрын
I am getting this error when i am submitting my soln in leetcode can anyone please help? AddressSanitizer:DEADLYSIGNAL ================================================================= ==30==ERROR: AddressSanitizer: stack-overflow on address 0x7ffef164fff8 (pc 0x000000345d18 bp 0x7ffef1650010 sp 0x7ffef1650000 T0) ==30==ABORTING
@adityan5302
@adityan5302 2 жыл бұрын
The above solution Time complexity is about N**2 * 9**(n*n) Python solution : O(N) : 9**(n*n) See only if you find difficulty in building the code m, n = 9, 9 res = [] def possible(x, y, c): x, y = int(x), int(y) for i in range(9): if arr[i][y] == c: return False if arr[x][i] == c: return False if arr[3*(x//3) + i//3][3*(y//3) + i%3] == c: return False return True def solve(row, col): if row == n: return True if col == n: return solve(row+1, 0) if arr[row][col] == ".": for i in range(1, 10): if possible(row, col, str(i)): arr[row][col] = str(i) if solve(row, col + 1): return True else: arr[row][col] = "." return False else: return solve(row, col + 1) solve(0, 0)
@shivanshkhare2724
@shivanshkhare2724 2 жыл бұрын
yes , n^2 is unnecessary increase in complexity.
@sbarbeloa
@sbarbeloa 3 жыл бұрын
thank you so much
@freshcontent3729
@freshcontent3729 3 жыл бұрын
what is the TC for this ques ? please explain , please help me , thanks..
@satendra6200
@satendra6200 10 ай бұрын
There are 6,670,903,752,021,072,936,960 possible solvable Sudoku 😅 grids that yield a unique result (that's 6 sextillion, 670 quintillion, 903 quadrillion, 752 trillion, 21 billion, 72 million, 936 thousand, 960 in case you were wondering). That's way more than the number of stars in the universe
@UECAshutoshKumar
@UECAshutoshKumar Жыл бұрын
Thank you sir
@adityan5302
@adityan5302 2 жыл бұрын
GREAT EXPLANATION :::::)))))
@shubhambhardwaj8894
@shubhambhardwaj8894 3 жыл бұрын
Thank you so much brother, please complete the sde sheet 🙏
@devbhattacharya153
@devbhattacharya153 2 жыл бұрын
Thanks a lot striver :)
@fantasyillusion
@fantasyillusion 2 жыл бұрын
If anyone's looking for [ python ] solution, then here it is class Solution: def solveSudoku(self, board: List[List[str]]) -> None: self.solve(board) def solve(self,board): for i in range(9): for j in range(9): if board[i][j]=='.': for c in range(1,10): if self.checkvalid(board,i,j,str(c))==True: board[i][j]=str(c) if self.solve(board)==True: return True else: board[i][j]='.' return False return True def checkvalid(self,board,row,column,c): for i in range(9): if board[i][column]==c: return False if board[row][i]==c: return False if board[3*(row//3)+i//3][3*(column//3)+i%3]==c: return False return True
@feliwx4087
@feliwx4087 7 ай бұрын
Awesomeee!!
@keertilata20
@keertilata20 2 жыл бұрын
thank you :)
@abhinavsingh9720
@abhinavsingh9720 2 жыл бұрын
Thanks
@anmolverma075
@anmolverma075 Жыл бұрын
Bhaiya ji , OP explnation!
@ramakrishnakcr4417
@ramakrishnakcr4417 4 ай бұрын
thank you🙏 for your work, if we send row number in every recursion that will improve the code execution time further
@SatyamKumar-bw4vi
@SatyamKumar-bw4vi 2 жыл бұрын
Hare Krishna! Great🙏🙏
@harshitjaiswal9439
@harshitjaiswal9439 5 ай бұрын
understood!
@krribss
@krribss 2 жыл бұрын
Great explanation! but it will only work for board size 9. A separate loop on ' board[3*(row/3) +i/3][3*(col/3) +i%3]==c ' can make it generic for all board size. Python Code: class Solution: def solveSudoku(self, board: List[List[str]]) -> None: N=len(board) for row in range(N): for col in range(N): if board[row][col]==".": for num in range(1,N+1): if(self.isValid(num,row,col,board,N)): board[row][col]=str(num) if(self.solveSudoku(board)): return True else: board[row][col]="." return False return True def isValid(self,num,row,col,board,N): for i in range(N): if str(num) == board[row][i]: return False if str(num) == board[i][col]: return False for i in range(9): if str(num) == board[3*(row//3) +i//3][3*(col//3) +i%3]: return False return True
@anushkachakraborty8635
@anushkachakraborty8635 Жыл бұрын
I really liked this approach. I was thinking how many N can we logically use? i think just 2(4*4 suduko),4(16*16 suduko) because total possible squares and time complexity will not support much beyond that without really intense computational powers.
@hrushikeshkale68
@hrushikeshkale68 3 жыл бұрын
Hey striver I have a question. In a book I read that by studying a topic with a gap makes it stick better in brain ex- Studying Graph today and taking a gap of 2 days and again studying graph. Should I follow it or just take a topic and continue everyday on same topic
@ishaanarora3279
@ishaanarora3279 3 жыл бұрын
yes it definitely happens. For example in my case I take 1 month gap and after again revising the topic I find them easy to code and I feel my thinking skills gets better for that topic after taking that break
@aaravarya4406
@aaravarya4406 2 жыл бұрын
It does.
@shivalikagupta3433
@shivalikagupta3433 2 жыл бұрын
Thank you sooo mcuh :)))) Awesome :}}
@dakshkriplani2935
@dakshkriplani2935 4 ай бұрын
I am impressed .
@vicharshukla7074
@vicharshukla7074 3 жыл бұрын
xcellent explanation bro,
@freshcontent3729
@freshcontent3729 3 жыл бұрын
what is the TC for this ques ? please explain , please help me , thanks
@culeforever5408
@culeforever5408 7 ай бұрын
understood 😇
@sbagul2
@sbagul2 Жыл бұрын
iterating through 3x3 matrix was awesome
@sanchitdeepsingh9663
@sanchitdeepsingh9663 6 ай бұрын
thanks sir
@biikaaa.6540
@biikaaa.6540 2 жыл бұрын
This is what i needed
@VinayKumarcs127
@VinayKumarcs127 Жыл бұрын
Genius!!
@mriduljain1981
@mriduljain1981 Жыл бұрын
this guy is godddddd hatss off man
@oqant0424
@oqant0424 Жыл бұрын
understood!!!!!!!!!
@LearningYouth
@LearningYouth Жыл бұрын
Nice explanation. Thanks However I looped through the 3x3 matrix and checked the row and column using another variable. I think the time complexity is still same as I'm only looping 9 times. here is the code: bool isSafe(int r, int c, int val, int grid[n][n]) { int idx = 0; int row = 3 * (r/3); int col = 3 * (c/3); for(int i = 0; i < 3; i++) { for(int j = 0; j < 3; j++) { if(grid[idx][c] == val) return false; if(grid[r][idx] == val) return false; if(grid[row+i][col+j] == val) return false; idx++; } } return true; }
@aryankumar3018
@aryankumar3018 Жыл бұрын
Understoooooood!
@VishalGupta-xw2rp
@VishalGupta-xw2rp Жыл бұрын
Bhaiiii sahabbb vo Box ka idea toh matlab bilkul *Kamal* tha bhai..... I'm just like you not only achieved your dream but helping others also to achieve theirs. *We must protect you at all cost brother* Such amazing explanation... Thankyou so much 🙏🙏🙏 You are indeed a blessing for us man
@koustubhsharma7483
@koustubhsharma7483 3 жыл бұрын
bro please jaldi jaldi upload karo btw great help
@jinhuang7258
@jinhuang7258 Жыл бұрын
Understood.
@skilz9525
@skilz9525 Жыл бұрын
for the 3x3 box checking I am still preferring the nested for loop rather than that formula, I know its not efficient but common we only have 9 values to check, so don't think it will make significant difference in runtime
L16. M-Coloring Problem | Backtracking
24:37
take U forward
Рет қаралды 184 М.
L14. N-Queens | Leetcode Hard | Backtracking
36:55
take U forward
Рет қаралды 368 М.
The child was abused by the clown#Short #Officer Rabbit #angel
00:55
兔子警官
Рет қаралды 25 МЛН
Каха и суп
00:39
К-Media
Рет қаралды 4,2 МЛН
Survival skills: A great idea with duct tape #survival #lifehacks #camping
00:27
I Can't Believe We Did This...
00:38
Stokes Twins
Рет қаралды 95 МЛН
Python Sudoku Solver - Computerphile
10:53
Computerphile
Рет қаралды 1,1 МЛН
L19. Rat in A Maze | Backtracking
25:10
take U forward
Рет қаралды 194 М.
N-Queens, N-Knights, Sudoku Solver (LeetCode) - Backtracking Questions
1:19:26
Valid Sudoku - Amazon Interview Question - Leetcode 36 - Python
13:28
Valid Sudoku - LeetCode 36 - Java
15:28
LeetCode University
Рет қаралды 2,8 М.
L1. Introduction to Sliding Window and 2 Pointers | Templates | Patterns
36:55
The child was abused by the clown#Short #Officer Rabbit #angel
00:55
兔子警官
Рет қаралды 25 МЛН