The N Queens Problem using Backtracking/Recursion - Explained

  Переглядів 133,170

Back To Back SWE

Back To Back SWE

5 років тому

Code - backtobackswe.com/platform/co...
Free 5-Day Mini-Course: backtobackswe.com
Try Our Full Platform: backtobackswe.com/pricing
📹 Intuitive Video Explanations
🏃 Run Code As You Learn
💾 Save Progress
❓New Unseen Questions
🔎 Get All Solutions
Question: Write a program which returns all distinct nonattacking placements of n queens on an nxn chessboard, where n is an input to the program.
A nonattacking placement of queens is one in which no two queens are in the same row, column, or diagonal.
We will use backtracking to solve this problem.
This can be one of the most confusing topics that you have to learn, expecially if you have shaky foundations in thinking recursively and calculating harder complexities.
Other Well Know Backtracking Problems:
-) Generate The Powerset of An Array (Subsets)
-) Generate All Permutations of A String
Backtracking/Recursion is about following a path to a base case...our target...our answer. If a certain path ends up not meeting our constraints we will backtrack to an earlier state and try something else from there.
The 3 Keys To Backtracking Problems:
Our Choice
-) What choice are we making at each call of the function
-) RECURSION REPRESENTS A DECISION.
-) RECURSION REPRESENTS A CHOICE & its associated state
-) Each function call represents a state. From that state decisions can be made.
Our Constraints
-) What tells us to stop following a certain path that we are searching on?
-) Have we exhausted all possibilities?
Our Goal
-) What is our target?
-) What are we trying to find?
-) These will craft our base cases.
Example: You lost your keys. Where do you go? The most recent place you were. Then the most recent place from there. And so on. Then you go to somewhere else...eventually you find your keys or give up the search.
So for this problem:
Our Choice - Where to place a queen
Our Constraints - The placement must non-attacking
Our Goal - Place n-queens on the chess board
Time and Space Complexities:
Complexity for this problem is tricky.
The time complexity is lower bounded by the number of non-attacking placements because we will be making at least the amount of function calls that it takes to find those placements (meaning we don't even include work done in each call).
No exact form is known for this lower bound as a function of n, but it is conjectured to tend towards n! / (c ^ n) (where c ≈ 2.54) which is super-exponential.
Super exponential growth forms a "J-curve" that grows much faster than exponential functions.
RECURSION REPRESENTS A DECISION.
RECURSION REPRESENTS A DECISION.
RECURSION REPRESENTS A DECISION.
Whether this is a tree or a linked list, etc. When thinking recursively, our function sets forth rules that allows the function to make decisions based on state passed into it
All backtracking is about is that we can return to previous decision points and explore another path that hasn't been taken yet to see if it yields an answer.
++++++++++++++++++++++++++++++++++++++++++++++++++
HackerRank: / @hackerrankofficial
Tuschar Roy: / tusharroy2525
GeeksForGeeks: / @geeksforgeeksvideos
Jarvis Johnson: / vsympathyv
Success In Tech: / @successintech
++++++++++++++++++++++++++++++++++++++++++++++++++
This question is question 16.2 in Elements of Programming Interviews (EPI).

КОМЕНТАРІ: 324
@BackToBackSWE
@BackToBackSWE 5 років тому
Table of Contents: (and more info) Video Setup 0:00 - 0:33 Introducing The N Queens Problem 0:33 - 1:05 What Is Backtracking? 1:05 - 2:15 Further Describing The Problem 2:15 - 3:21 The 3 Keys To Backtracking Problems 3:21 - 5:31 The Code 5:31 - 13:11 Wrap Up 13:11 - 14:09 The N Queens Problem Made Simple. Forgot to explain time complexities, that is in the description. Also, I wish I could've drawn a full diagram of the backtracking but ran out of room on the board. I may make a separate video for that since VISUALS are very key for understanding how these backtracking algorithms work.
@alihaghighipour7371
@alihaghighipour7371 4 роки тому
you're by far the most enthusiastic person that i've ever seen in this field dude . keep it up !
@BackToBackSWE
@BackToBackSWE 4 роки тому
I was mad lol, because online explanations sucked
@qwarlockz8017
@qwarlockz8017 3 роки тому
@@BackToBackSWE Also, your code for this is the cleanest and clearest that I have seen. I have searched through github and no one has better code for this excersize.
@naydernn4725
@naydernn4725 2 роки тому
I can tell this explanation is coming from someone who struggled a long time with the concept, because your explanation is so thorough yet accommodating that it is hard not to kind of get it as I follow along.. Thank you so much!
@BackToBackSWE
@BackToBackSWE Рік тому
Thank you, glad you liked it 😀 Do check out backtobackswe.com/platform/content and please recommend us to your family and friends 😀
@BarnezGFX
@BarnezGFX 5 років тому
This is a brilliant example, and it's evident you care about what you are teaching - which is greatly appreciated and reflected in the quality of the video. Thanks a lot, it helped me get a little bit closer to understanding.
@BackToBackSWE
@BackToBackSWE 5 років тому
Great. That means a lot. My goal is to make this the premier channel (#1 on UKposts) for programming interview prep. Teaching is hard and I'm slowly getting better at it. If you are still not 100% give it a few months and come back. Concepts that are new like this take time to sink in, but once they are internalized they stay for a long time in understanding.
@jiadar
@jiadar 3 роки тому
I've never seen someone so excited about algorithms. Great content. Well done!
@NithinMWarrier
@NithinMWarrier 2 роки тому
I really love the way you explain, your commitment to understand is amazing, a big thumbs up man!!
@YashSharma-uw8dn
@YashSharma-uw8dn 4 роки тому
I really like the informalness that you bring while making videos on dense topics, trust me that really helps the viewers 😁
@BackToBackSWE
@BackToBackSWE 4 роки тому
thx
@danielg012
@danielg012 5 років тому
These videos have been super helpful for me during my interview prep. Thank you so much!
@BackToBackSWE
@BackToBackSWE 5 років тому
It is nothing. If you ever have any questions just comment on a video and I can answer them (I check these daily). I am literally here for you. Although we may not know each other I know exactly what you are going through. This is why the channel exists and why I do this.
@finncummins6230
@finncummins6230 4 роки тому
Hey man, I love the great quality of these videos and the depth to which you explain each topic. I am currently studying for a competitive programming competition and I'm finding your videos to be a great study aid. Keep up the good work!
@BackToBackSWE
@BackToBackSWE 4 роки тому
Nice! Keep it up, you are a beast!
@eggsaladstuckcrafts4653
@eggsaladstuckcrafts4653 4 роки тому
Thank you so much for making this video. I was so confused about where to even start with my backtracking project for class but this helped me so much!
@BackToBackSWE
@BackToBackSWE 4 роки тому
sure
@ericlugo-dev
@ericlugo-dev 3 роки тому
Absolutely love the way this was explained. I've been ramming my head at the wall that is understanding recursion for a bit without much progress, yet this explanation completely changed the way I treat it!!!
@BackToBackSWE
@BackToBackSWE 3 роки тому
great to hear
@gmstabloid
@gmstabloid 4 роки тому
You should be proud man! Awesome explanation and passion for the code! Thanks!
@BackToBackSWE
@BackToBackSWE 4 роки тому
thanks
@xinyuyou7512
@xinyuyou7512 5 років тому
I really feel your enthusiastic when you're making this video. This helps me continue Learning the video. Thank you so much.
@BackToBackSWE
@BackToBackSWE 5 років тому
haha, sure
@jayliang5737
@jayliang5737 4 роки тому
You get the clearest explanation for backtracking I can find on youtube!
@BackToBackSWE
@BackToBackSWE 4 роки тому
thx
@marisawong644
@marisawong644 7 місяців тому
i love this man - he explains everything so well!
@Ayushkumar-xj9vl
@Ayushkumar-xj9vl 4 роки тому
Thanks for this briliant insight to recursion, you explain like a big bro.😃
@BackToBackSWE
@BackToBackSWE 4 роки тому
sure
@IlyaBoytsov-dt8lt
@IlyaBoytsov-dt8lt 4 роки тому
Hi, Ben. Starting watching your videos during new year holidays was a great idea for me. Before that I was watching different algorithm tutorials on youtube, but it can`t be compared with your effort and explanations. Hope to see more from you, my special wish to your channel is to make more videos of new and latest problems that come from different companies interviews. It is important for learning because some problems are "classic" and despite of the fact that intuition behind them is still of crucial importance, that would be nice to have some "fresh" problems! Or maybe some variations of older problems... One more time thank you, i am going to join your coding interview class and keep learning. Best wishes from Russia, Ilya
@BackToBackSWE
@BackToBackSWE 4 роки тому
Thanks :)
@rajrajeshwarsinghrathore
@rajrajeshwarsinghrathore Рік тому
Thanks a lot. This was my first LeetCode HARD problem. Gave a much-needed confidence.
@vinithapalani3385
@vinithapalani3385 4 роки тому
Have watched half a dozen of videos on this ...but only after watching this can I confidently say that I "get it" ..Thanks you so much, you are awesome!!
@BackToBackSWE
@BackToBackSWE 4 роки тому
nice!
@hackerandpainter
@hackerandpainter 3 роки тому
you are a skinny legend dude. love your videos pls keep it up!! would love to see a vid on strongly connected components/ tarjan algorithm from you
@karankanchetty105
@karankanchetty105 4 роки тому
Wow. You just boiled a hard problem down to 3 simple steps that we can always rely on. Thanks for the video and an awesome explanation.
@BackToBackSWE
@BackToBackSWE 4 роки тому
sure, thanks for coming by
@sarthakbhatia7888
@sarthakbhatia7888 3 роки тому
Thanks mann....Your explaination is really one of the best out there!!
@BackToBackSWE
@BackToBackSWE 3 роки тому
thanks!
@satyadeeproat2012
@satyadeeproat2012 3 роки тому
Really good explanation to divide backtracking problems in goals, choice and constraint. Backtracking problems get really easy thinking in this way
@BackToBackSWE
@BackToBackSWE 3 роки тому
yeah
@RK-nw1nq
@RK-nw1nq 4 роки тому
Such a great explanation and your energy, it was amazing which really helps in understanding the concept better. GREAT WORK!!
@BackToBackSWE
@BackToBackSWE 4 роки тому
thanks
@takharamazanpolat7610
@takharamazanpolat7610 4 роки тому
I'm watching this channel's video first time but I can say that this man has a passion for what he does, it can be seen in the first couple of minutes.
@BackToBackSWE
@BackToBackSWE 4 роки тому
Welcome to da pardy
@user-ku2kq9hb5u
@user-ku2kq9hb5u Рік тому
this is supper clear, thank you for making these videos
@ameerkaras4580
@ameerkaras4580 3 роки тому
These have got to be the only genuinely entertaining coding vids on the internet, love it
@BackToBackSWE
@BackToBackSWE 3 роки тому
ye - i luv the internets
@TanujMishra077
@TanujMishra077 5 років тому
Great explanation. You guys are awesome. Keep up the good work. Subscribed.
@BackToBackSWE
@BackToBackSWE 5 років тому
thanks
@lilaiyang5745
@lilaiyang5745 2 роки тому
Please keep doing more problems, only your video makes me understand N-Queens Problems. Appreciate it!
@BackToBackSWE
@BackToBackSWE 2 роки тому
Amaze! Stay tuned for our upcoming interview prep module with new mentors!
@eltonmurillo1909
@eltonmurillo1909 3 роки тому
thanks for the video. thank you for drilling the principles! this helps tremendously. recursion can get pretty difficult. the longer you think about it the more confusing it gets lol...
@shriyadas925
@shriyadas925 4 роки тому
Awesome explanation. Best video on this topic! Loved it!
@BackToBackSWE
@BackToBackSWE 4 роки тому
thanks
@vraih4847
@vraih4847 4 роки тому
You simplified such a difficult problem to a clean and simplified solution....Amazing!!! And the github code is commented so well, I didn't find any difficulty understanding it. Keep up this good work bro...appreciate it!!!
@BackToBackSWE
@BackToBackSWE 4 роки тому
ye, go flourish internet friend
@AdtecBarema
@AdtecBarema 4 місяці тому
This is Just Superb, thank you so much Biny for all effort & kindness, in demistyfying this involved problem.
@jjlovekdw
@jjlovekdw 4 роки тому
Thank you so much for explaining this problem, vert easy to understand and very useful for my preparation of my whiteboard interview. Hopeful it will goes will next week.
@BackToBackSWE
@BackToBackSWE 4 роки тому
thanks and best of luck
@svdfxd
@svdfxd 5 років тому
As usual very nice explanation. And a big thanks to your buddy who films all videos religiously.
@BackToBackSWE
@BackToBackSWE 5 років тому
hahaha, it is a religion at this point
@bokams3385
@bokams3385 3 роки тому
It’s superb analysis ,I have gone through a lot of blogs sites but I couldn’t understand finally I understand thanks a lot ,keep rocking
@BackToBackSWE
@BackToBackSWE 3 роки тому
sure
@manasasusirla6451
@manasasusirla6451 3 роки тому
I bet there's no one who can explain backtracking problem better than you did. Your video helped me a lot. Thanks!
@BackToBackSWE
@BackToBackSWE 3 роки тому
sure!
@sanjivmadhavan5705
@sanjivmadhavan5705 4 роки тому
AWW THIS VIDEO WAS POSTED ON MY BIRTHDAY. THANKS FOR THE GIFT MY MAN
@BackToBackSWE
@BackToBackSWE 4 роки тому
nice yo
@27k76
@27k76 4 роки тому
Excellent video as always, planning to join your class soon. Might join next month , a little busy this month unfortunately.
@BackToBackSWE
@BackToBackSWE 4 роки тому
Yeah thx, and nice
@Paradise-kv7fn
@Paradise-kv7fn 5 років тому
I liked the tutorial series...I saw your subset and permutation videos and I somehow managed to come up with the solution to this problem all by myself...so thanks for the wonderful explanation of this topic...however, I couldn't come up with all the possible placements for the queen
@BackToBackSWE
@BackToBackSWE 5 років тому
Nice. And what do you mean by " I couldn't come up with all the possible placements for the queen". Like you coded it and it has a bug or you don't understand or...yeah...confused.
@Paradise-kv7fn
@Paradise-kv7fn 5 років тому
@@BackToBackSWE currently my solution gives me only 1 possible arrangements...but i was unable to modify it so that it returns me the total numbers of possible valid arrangements for a given nxn board...can you help me on that? I was thinking of calling our helper function for each column in the first row i.e for each cell in the first row....that will ensure that we cover all possible cases and not just return trie when we find our first valid arrangement....but before calling helper function with a new column value in the first row, we will check if it has already not been peocessed as a valid position by one of our previous calls to the helper function... but i am.not sure if it would work
@BackToBackSWE
@BackToBackSWE 5 років тому
@@Paradise-kv7fn check other solutions on Leetcode, I'd love to help but I'm busy-ish today
@avrillovugne
@avrillovugne 5 років тому
Thank you Ben, great explanation!
@BackToBackSWE
@BackToBackSWE 5 років тому
sure
@jayram.deshpande
@jayram.deshpande 2 роки тому
amazingly explained ! Bravo !
@shikharsaxena4432
@shikharsaxena4432 4 роки тому
Thanks a lot for such an amazing explanation, I have my coding round for Twitter this week, I hope I clear it. 🤞
@BackToBackSWE
@BackToBackSWE 4 роки тому
ye
@nico-bf8ql
@nico-bf8ql Рік тому
thank u so much. i love how causal and inviting you are
@BackToBackSWE
@BackToBackSWE Рік тому
Glad it was helpful! 😄 Also check out our FREE DSA Interview Prep Mini-Course - backtobackswe.com/ 🎉
@0x1h0b
@0x1h0b 5 років тому
back tracking is a real pain. but you made it look so easy . thank you man !... waiting for more interview problems like this........:-)
@BackToBackSWE
@BackToBackSWE 5 років тому
sure
@jacksonsouza5232
@jacksonsouza5232 5 років тому
Very clear explanation of backtracking at the beginning, thanks!
@BackToBackSWE
@BackToBackSWE 5 років тому
Thanks, much love.
@teki9845
@teki9845 2 роки тому
Amazing video man , thank you so much !!!!!!!!
@jomosis9234
@jomosis9234 4 роки тому
I love your explanation for backtracking problems. Now I've got a good understanding of the frame of doing such kind of problem, thank you so much!!! But one more thing I want to make sure is that whenever a backtracking function call is exhausted,it returns to its higher layer stack, is undos the first thing that it will execute? For example: backtrack(...) undos let's say backtrack(1) return to backtrack(2) ,it will undo what it did to " 1 ",and then keep backtracking. Do I get it? For more complicated backtracking problems: backtrack 1 some orders backtrack 2 these 2 backtracking calls are different. If backtrack 1 is exhausted. Does the process work like this: backtrack 1 returns to the previous stack, then execute these orders, and then do the backtrack 2 until it is also exhausted , and then return to the next previous stack of backtrack 1. If some orders are undos , will this process change?
@BackToBackSWE
@BackToBackSWE 4 роки тому
can you consolidate your question, it is hard to parse this all
@prashant211087
@prashant211087 4 роки тому
When you reach the end of this playlist... Backtrack :)
@BackToBackSWE
@BackToBackSWE 4 роки тому
indeed
@user-wc1sm8cj8s
@user-wc1sm8cj8s 3 роки тому
LOL
@ruchikasalwan1285
@ruchikasalwan1285 4 роки тому
Good one! Explained really well!
@BackToBackSWE
@BackToBackSWE 4 роки тому
thx
@ismailahmad9597
@ismailahmad9597 Рік тому
The concept was tough enough that I had to rewind a few times, pause, and think. But the explanation, method of presentation, and such was amazing. Thanks a ton!
@ismailahmad9597
@ismailahmad9597 Рік тому
The dynamic with the camera man is fun too
@pablogalindo2089
@pablogalindo2089 3 роки тому
I love the way you teach!! very helpful
@BackToBackSWE
@BackToBackSWE 3 роки тому
thx
@joshwahnon854
@joshwahnon854 2 роки тому
Very clear, very well explained. Can you do a video on the use of DPLL algorithm and what types of problem to use it on?
@BackToBackSWE
@BackToBackSWE 2 роки тому
You can subscribe to our DSA course with a flat 30% off for some amazing content b2bswe.co/3HhvIlV
@rahulsaxena9103
@rahulsaxena9103 4 роки тому
You are awesome!!. Such a lucid explanation!
@BackToBackSWE
@BackToBackSWE 4 роки тому
thanks
@NaveenKumar-os8dv
@NaveenKumar-os8dv 2 роки тому
10:38 You don't know how much I needed to understand that part. Thank you!! I was so confused. I just didn't know "HOW TO BACTRACK" The most confusing part for me was : :how the heck making it equal to null(or zero - meaning removing it(our choice)) makes our function go back?? Yeah I can find one way or n way to place queens, but how to find all of them?? and that's where your video help me, I missed the point that the loop is always increasing, if my choice is removed next time it will choose for col+1 and (not the 'col' instead).
@adhoc3018
@adhoc3018 3 роки тому
Brilliant explanation.
@Ty1er
@Ty1er 3 роки тому
Awesome work Helped me A LOT THANKS 🤍
@vivek4490
@vivek4490 3 роки тому
awesome explanation!
@krishnapathi572
@krishnapathi572 3 роки тому
That is a damn good explanation and awesome energy bro :)
@BackToBackSWE
@BackToBackSWE 3 роки тому
thx
@ogbonnakingsley9908
@ogbonnakingsley9908 3 роки тому
Great explanation. I have a newbie question though. Why do we need to backtrack on every iteration of the for-loop. What if the last choice made was correct. What purpose does undoing the choice serve? You made a statement about the program continuing from the last point of the stack. How does undoing our choice serve that purpose?
@IkethRacing
@IkethRacing Рік тому
because the alternative is keeping a complete board representation for each move which gobbles up your ram
@ipals1234
@ipals1234 4 роки тому
The way you explain details is very good. A small suggestion for code: you can keep both add and remove colPlacements inside if loop, it would avoid adding and removing current col to colplacements list if the valid Placement is false.
@BackToBackSWE
@BackToBackSWE 4 роки тому
ok
@Palmoghe
@Palmoghe 5 років тому
Appreciate the passion and efforts. Kudos to you two! ++Subscribers :)
@BackToBackSWE
@BackToBackSWE 5 років тому
hola mi amigo
@F.R.A.N.K.I.E
@F.R.A.N.K.I.E 3 роки тому
You're nothing less than a hero, thank you!
@farhanuddinkazi3051
@farhanuddinkazi3051 5 років тому
Thanks, it was really helpful.
@BackToBackSWE
@BackToBackSWE 5 років тому
sure
@muralivenuthyagarajan5767
@muralivenuthyagarajan5767 5 років тому
Awesome explanation. Easy to understand.
@BackToBackSWE
@BackToBackSWE 5 років тому
thanks
@heyyyyyworld
@heyyyyyworld 2 роки тому
Thank you!!!!
@a_k__
@a_k__ 4 роки тому
Amazing job man. Well done.
@BackToBackSWE
@BackToBackSWE 4 роки тому
ye
@a_k__
@a_k__ 4 роки тому
@@BackToBackSWE It would have been great if you could make a video about the behavioral/phone screen part of the interview for SWE as well.
@BackToBackSWE
@BackToBackSWE 4 роки тому
@@a_k__ ok
@josephwong2832
@josephwong2832 4 роки тому
Love your teaching style bro
@BackToBackSWE
@BackToBackSWE 4 роки тому
thx
@nishantjain2128
@nishantjain2128 4 роки тому
Man these 3 points are really great... i am able to solve now various backtracking problems on my own
@BackToBackSWE
@BackToBackSWE 4 роки тому
great to hear
@ziedbrahmi4812
@ziedbrahmi4812 Рік тому
THANK YOU
@bhushanshinde4227
@bhushanshinde4227 2 роки тому
Good job boy!
@siddhantsharma6747
@siddhantsharma6747 4 роки тому
Dude I have no idea how you don't have 1M subscribers by now.
@BackToBackSWE
@BackToBackSWE 4 роки тому
The channel is young and niche. We do not have content that scales yet.
@hezekiahbranch5461
@hezekiahbranch5461 4 роки тому
Agreed!!
@vigneshkrishnan3192
@vigneshkrishnan3192 4 роки тому
Get a guy who does good video editing. your channel will surely sky rocket.
@airysm
@airysm 5 років тому
I think my problem with recursive problems is how to format my code if that makes sense, like how many helper functions to make and what parameters are each going to take. Any tips for that? Btw I forgot how I found your channel, but I love the vids!
@BackToBackSWE
@BackToBackSWE 5 років тому
Yes, this is the hardest part. Thinking recursively took me SEVERAL months to understand and become proficient at. Some just get it, some don't. I didn't. 1.) The more practice you do and the more problems you see, the better you will get at defining base and recursive cases. This is sadly true, a lot of work. 2.) Before even making a driver function, I scaffold out the signature of the recursive helper function. The biggest things that influence this are #1 and #3 of the "keys" I mentioned, your Choices & Goal. In this problem you see we pass in a "colPlacements" array to remember our CHOICES as well as the row # that we are working on and a "result" array to remember our answers, etc. It is not always this straightforward but the key is to ask. "What subproblems am I solving and what do I need in each to make things work?" For this problem a subproblem is solving a row. When n rows are solved we are done. So that's definitely a param and will be used in the base case since it is our GOAL. Otherwise it is just practice, trial and error, and eventually proficiency increases greatly.
@adipratapsinghaps
@adipratapsinghaps Рік тому
if -> our goal else -> loop (pick a choice, check constraints [if valid, go deeper], undo choice) Sweet!!!
@prince26902690
@prince26902690 2 роки тому
excellent vidoe.. want to understand the math behind IsValid? Any pointers?
@srikantsharma6430
@srikantsharma6430 4 роки тому
Appreciate your hard work.
@BackToBackSWE
@BackToBackSWE 4 роки тому
thanks
@anjurawat9274
@anjurawat9274 4 роки тому
very helpful and as I always say.. I love ur way of teaching sir
@BackToBackSWE
@BackToBackSWE 4 роки тому
hey
@anjurawat9274
@anjurawat9274 4 роки тому
@@BackToBackSWE helo sir i sent u a msg request on ur fb page please check out
@nocode659
@nocode659 4 роки тому
First video of you i Watched and subscribed! DOT
@BackToBackSWE
@BackToBackSWE 4 роки тому
welcome!
@ramansb1008
@ramansb1008 2 роки тому
ayyy ur a boss, I was struggling on this shit man !
@BackToBackSWE
@BackToBackSWE Рік тому
Thank You, Glad you liked it. Do check out backtobackswe.com/platform/content and please recommend us to your family and friends :)
@tlj77
@tlj77 4 роки тому
Really nice, thanks man
@BackToBackSWE
@BackToBackSWE 4 роки тому
sure
@siddhantrai7529
@siddhantrai7529 4 роки тому
Brilliant explanation
@BackToBackSWE
@BackToBackSWE 4 роки тому
thanks
@chrisqin8780
@chrisqin8780 3 роки тому
Hey thank you so much for this amazing video. However, I tried your code on my IDE and I guess if you add a return after you add the colPlacements to your result, it will be better right?
@BackToBackSWE
@BackToBackSWE 3 роки тому
I dont remember the code
@holyshit922
@holyshit922 4 роки тому
Solution for another chess problem known as Knight's tour can be found in Wirth's Algorithms + data structures = programs It also uses backtracking
@BackToBackSWE
@BackToBackSWE 4 роки тому
thank you
@anmolmishra1914
@anmolmishra1914 4 роки тому
I do have weak roots in recursion, I am an undergrad, How did you improve your recursion? (What to do while practicing?) i don't use FB else I would have asked the same on the group, I don't see any other to ask a question. Sorry for trouble like this.
@BackToBackSWE
@BackToBackSWE 4 роки тому
Do a ton of problems until it is seared into your soul. And no, this is the best place to ask questions.
@jonathandaniel7321
@jonathandaniel7321 4 роки тому
what did the trick for me is trusting the recursive calls, put the base case above it and it will always work, just trust it
@sandile13809
@sandile13809 2 роки тому
ur epic bro thank you sm
@SlowMister112
@SlowMister112 3 роки тому
the nqueens can also be solved by using a knight layout: queens can attack like every other unit except the knight, so if one finds out a combination exclusively for knights it solves the nqueens too
@madiyar8079
@madiyar8079 4 роки тому
amazing, thank you
@BackToBackSWE
@BackToBackSWE 4 роки тому
sure
@mayankdandwani9951
@mayankdandwani9951 4 роки тому
Bro your explanations are damn good !!!!!!!!!!!
@BackToBackSWE
@BackToBackSWE 4 роки тому
thanks
@Milchmann2
@Milchmann2 5 років тому
Beautiful!
@BackToBackSWE
@BackToBackSWE 5 років тому
hola
@Tatseryu27
@Tatseryu27 4 роки тому
My gosh, this is exactly what I was looking for. I'm gonna use it for my presentation tomorrow.
@BackToBackSWE
@BackToBackSWE 4 роки тому
nice
@geetusharma3923
@geetusharma3923 3 роки тому
Awesome video 👌.. thanks a lot .🔥. please upload more videos...
@BackToBackSWE
@BackToBackSWE 3 роки тому
thanks sure and sure
@lokeshs9449
@lokeshs9449 3 роки тому
Your'e BackTracking Hero Man
@BackToBackSWE
@BackToBackSWE 3 роки тому
thanks lol, always wanted to be that
@HarshSingh-zf7tw
@HarshSingh-zf7tw 4 роки тому
Ben I know its too much to ask but it would be very helpful for beginners if u would dry run your code on a small test case , so that that your theory can be seen how it is implemented in practicality .
@BackToBackSWE
@BackToBackSWE 4 роки тому
How so? Elaborate, I kinda get what u mean
@paulancajima
@paulancajima Рік тому
Thanks
@kevinsu2219
@kevinsu2219 5 років тому
nice explanation
@BackToBackSWE
@BackToBackSWE 5 років тому
Thank you!
@tandonneeraj
@tandonneeraj 4 роки тому
Very clear explanation.
@BackToBackSWE
@BackToBackSWE 4 роки тому
thanks
@tandonneeraj
@tandonneeraj 4 роки тому
​@@BackToBackSWE Is the code shown working. What if the row results in no solution. For if row[0] = 0 , row[1] = 2 then row[2] has no solution. It should backtrack with remove but for some reason I do not reach the solution.
@Paradise-kv7fn
@Paradise-kv7fn 5 років тому
I just got an interview call for amazon sde through hackerearth hiring challege...however, the interview is scheduled on 1st June :/ Now I have been preparing for interviews since around 20-25 days but I dont think that I am ready for all rounds of amazon level interviews...they are not reimbursing for the travel as well...so I am in a dilemma whether I should even go or not :/ are there any important topics that I should completely focus on for the next 2 3 days?
@BackToBackSWE
@BackToBackSWE 5 років тому
everything you are weak at
@guptabhi123
@guptabhi123 4 роки тому
I am learning the concepts of backtracking - This is what I understood. We remove the placement at the end in the for loop so as to try for other possibilities. However, what if the placement is correct, we still end up removing it right? Why does that work? Also, if we add the row to the result list, and if filling those numbers in that row was not correct, then how do we undo the choices that are already added to the result? Can someone please help with the core idea behind the above 2 points?
@BackToBackSWE
@BackToBackSWE 4 роки тому
"However, what if the placement is correct, we still end up removing it right? Why does that work?" Trace the recursion in your head. It will become apparent. "Also, if we add the row to the result list, and if filling those numbers in that row was not correct, then how do we undo the choices that are already added to the result?" Trace the code. It will be clear. Print things out.
@naveen3192
@naveen3192 2 роки тому
Do we undo our choice to get a new set of result? Or why do we do that?
@rozzero9664
@rozzero9664 4 роки тому
hats off to you .. you are the first non Indian tutorial channel
@BackToBackSWE
@BackToBackSWE 4 роки тому
uh
The Backtracking Blueprint: The Legendary 3 Keys To Backtracking Algorithms
13:44
How To Permute A String - Generate All Permutations Of A String
28:37
Back To Back SWE
Переглядів 109 тис.
Normal vs Smokers !! 😱😱😱
00:12
Tibo InShape
Переглядів 16 млн
N-Queens - Backtracking - Leetcode 51 - Python
17:51
NeetCode
Переглядів 141 тис.
6.1 N Queens Problem using Backtracking
13:41
Abdul Bari
Переглядів 1,8 млн
5 Simple Steps for Solving Any Recursive Problem
21:03
Reducible
Переглядів 1,1 млн
The 8 Queen Problem - Numberphile
7:04
Numberphile
Переглядів 1,5 млн
L14. N-Queens | Leetcode Hard | Backtracking
36:55
take U forward
Переглядів 337 тис.
Towers of Hanoi: A Complete Recursive Visualization
21:13
Reducible
Переглядів 433 тис.
Can you solve this chess puzzle? (8 Queens problem)
10:10
Double D
Переглядів 24 тис.
The Last Algorithms Course You'll Need by ThePrimeagen | Preview
16:44
Frontend Masters
Переглядів 298 тис.
Вы поможете украсть ваш iPhone
0:56
Romancev768
Переглядів 362 тис.
How Neuralink Works 🧠
0:28
Zack D. Films
Переглядів 26 млн
Игровой ноутбук за 100тр в МВИДЕО
0:58
KOLBIN REVIEW
Переглядів 681 тис.
Самая важная функция в телефоне?
0:27
Опросный
Переглядів 177 тис.
Портативная PS 5 🎮 #ps5 #expressly
0:22
ExpresSLY Shorts
Переглядів 289 тис.