Table of Contents: Beginning The Backtracking Discussion 0:00 - 1:08 The 3 Keys To Backtracking 1:08 - 2:40 The Choice: Defining Our Decision Space 2:40 - 5:50 The Constraints: Directing Our Recursion 5:50 - 7:42 Our Goal: When Recursion Bottoms Out 7:42 - 9:22 Lesson Summary 9:22 - 10:52 How Do We Know When We Can Use Backtracking 10:52 - 12:07 Wrap Up 12:07 - 13:25 I don't like the word "blueprint" for these problems. There are patterns, I agree. But memorization of code snippets and patterns will rob you of true learning. You won't learn how to think on your own. Don't learn templates, know what is going on deeply. The code for the Sudoku solver problem is in the description.
@BackToBackSWE5 жыл бұрын
@shaurya pratap singh Depends. Like...this is hard to answer. What I focus on is Big N companies and these kinds of questions. For any other job in tech I really am not sure...it depends what you want to do. But yes, if you can do these then it basically proves you have the intellectual prowess to learn any tools used on the job. Much much easier to go from being a computer scientist to being a software engineer, than to go from web development to being a computer scientist.
@BackToBackSWE5 жыл бұрын
@shaurya pratap singh sure
@surbhigupta34034 жыл бұрын
A video on Dynamic programming blueprint as well
@bberger78584 жыл бұрын
There is no code in the description
@smritisrivastava40364 жыл бұрын
I can't find the link to your code
@airysm5 жыл бұрын
“Our for loop is for exploration in the stack frame” thanks for phrasing it like that it makes a lot of sense to me now
@BackToBackSWE5 жыл бұрын
yeah, I knew people would like that. I had that sentence circulating in my brain before I did this video (I had no script)...so I made sure I said it.
@tweede555522 күн бұрын
Hey man, long time subscriber here. 3 years ago I watched most videos on your channel and you are by far the greatest teacher I've had. I wish more people in the industry taught like you did - Clear and concise! You helped me crack my FAANG new grad interview, and now I'm back to get some refreshers to crack another FAANG possibly 😂. Just wanted to shout you out before I started my journey. THANK YOU! 🙏🏿
@colloidalsilver1775 жыл бұрын
bro can you all make every video from now on like this?..... i love the graphics .... putting the code on the screen is major key
@BackToBackSWE5 жыл бұрын
I wish I could. This took 7 hours. I...I really wish I could make everything top notch and it is annoying...but yeah I will continue to mix things up :)
@extremelyhappysimmer3 жыл бұрын
i love that your torso just blends into the background with the white shirt and you are just a benevolent set of floating body parts teaching us how to not fail finals tomorrow.
@vatsalhirpara58695 жыл бұрын
I love your teaching approach, not directly jumping to solutions but showing entire thought process.
@BackToBackSWE5 жыл бұрын
thanks
@sharmynkayani49625 жыл бұрын
I am so happy I found this channel! Dynamic Programming scares me but I am determined to combat that scare and these videos will help for sure. Thanks heaps :D
@BackToBackSWE5 жыл бұрын
nice
@patrickmayer9218 Жыл бұрын
*3 Keys: Choice, constraints, and goal. *Choice - Think about the choice you are making at every step *Constraints - What rules the choice must follow *Goal - What base case needs to be reached? *Backtracking is essentially just recursing on your decision if you screw up. *Look for words like "generate all" and "compute all". That will indicate backtracking is a good idea. Thanks for the video!
@BackToBackSWE11 ай бұрын
Happy Holidays 🎉 Thank you for your kind words! We'd love to offer you a 40% Off our exclusive lifetime membership just use the code CHEER40 - backtobackswe.com/checkout?plan=lifetime-legacy&discount_code=CHEER40
@Hank-ry9bz3 ай бұрын
to master recursion, make sure that your first master recursion
@animeshjaiswal30395 жыл бұрын
Sometimes we see things that are so splendid that we are out of words to express.And right now I am. Thanks for this awesome video.
@BackToBackSWE5 жыл бұрын
haha nice, thanks
@MohakNarang07 Жыл бұрын
I watched this video about a month ago when I was trying to get my head around backtracking but couldn't understand much. After solving a bunch of problems on Leet Code over the past month, I'm watching this video again, and surprisingly, it makes a lot more sense now xD Thanks a lot!
@BackToBackSWE Жыл бұрын
Glad it was helpful! 😄 Also check out our FREE DSA Interview Prep Mini-Course - backtobackswe.com/ 🎉
@BharCode094 жыл бұрын
You are not teaching, you healing. The way you approach and progress towards the solution, putting yourself in our shoes like "how easy/difficult it would be to understand what I'm saying". As if you totally understand the situation we are in. I bow for that empathy! 👐🙏
@BackToBackSWE4 жыл бұрын
thanks haha
@Anand-wi4yb5 жыл бұрын
0 Dislikes tells that how much people like the way you explain.
@BackToBackSWE5 жыл бұрын
Aw, thanks haha
@deepambanerjee37164 жыл бұрын
This is how you become humble and knowledgable at the same time
@BackToBackSWE4 жыл бұрын
haha nice
@optimizedpran12474 жыл бұрын
THIS MAN IS A LITERAL LEGEND. May you be blessed with glory in all three worlds.
@BackToBackSWE4 жыл бұрын
I am normal
@optimizedpran12474 жыл бұрын
@@BackToBackSWE hahahaha ik ik. honestly thanks for giving back to the community.
@gabrielacarrillo29424 жыл бұрын
Hey just wanted to let you know that this video is INCREDIBLY helpful. I had an onsite interview with Google and this legit helped me solve 3 out of the 5 questions they asked me. Without ever seeing the problem before, I used this methodology and was able to solve the problems. HUGE thanks
@BackToBackSWE4 жыл бұрын
sure
@nilanjanmukherjee42195 жыл бұрын
Beautiful explanation. Almost feels criminal that it isn't a paid course or content..I struggled for sometime on most DP tutorials mostly because they were focusing on what to do and not why.
@BackToBackSWE5 жыл бұрын
hahah, I do have a paid course that I'm growing right now. But yeah, all the videos here are the property of the internet and mankind now.
@EsotericArnold4 жыл бұрын
This is hands down the best description I've heard on helper method recursion/backtracking.
@BackToBackSWE4 жыл бұрын
thx
@josephwong28324 жыл бұрын
Finally someone who could explain this to me in a way I actually understood...
@BackToBackSWE4 жыл бұрын
ye
@luisasanchez92672 жыл бұрын
Man, your videos are really helpful. The way you explain it, your passion and your attitude is pure gold.
@BackToBackSWE2 жыл бұрын
Thanks! you could always try the 5 day free mini course for some awesome content - backtobackswe.com/
@jacobsummerz62 жыл бұрын
This guy is helping us learn while also practicing to become a weather man
@krishanbhansalee83695 жыл бұрын
Hi Ben, You are really doing great job. The way you explain the problem, make it very easy to understand and sink.It not only help us to understand the thought process but also bringing interest in to solving this type of problems. Your video's are the best among all the you tube videos which i have seen so far. I really appreciate you and your friend's effort for bringing out such a awesome contents.
@BackToBackSWE5 жыл бұрын
It's just me now, but yeah...thanks :)
@falakchudasama97465 ай бұрын
Good channels are often underrated man! I am glad I explored your channel and got a ton of quality information, hope your channel grows!!
@garvjain14504 жыл бұрын
Not the hero we deserve, but the hero we need...
@BackToBackSWE4 жыл бұрын
lol thx
@guruvigneshnagaraj85014 жыл бұрын
Thank you for providing a template for the backtracking problems. As an aspiring software engineer, this helps a lot!
@BackToBackSWE4 жыл бұрын
great to hear.
@AzharulIslamParvez4 жыл бұрын
I absolutely love your videos. Your explanations are just spot on. Your videos are the reason why I feel like I am getting a hold of difficult topics like recursion, DP, and backtracking. Great work dude!
@BackToBackSWE4 жыл бұрын
Nice
@dosatross5 жыл бұрын
you're a legend mate..better explanations than 95% of my uni profs
@BackToBackSWE5 жыл бұрын
Give me 1-3 years...the legend will continue.
@priyaljhaveri9320 Жыл бұрын
This is such a simplified approach to backtracking! Hope you start making videos again!
@kuralamuthankathirvelan5 жыл бұрын
These three keys are very useful inorder to find a pattern to solve any backtracking the problem !...Thanks a Ton bro !
@BackToBackSWE5 жыл бұрын
sure
@pranavkrishna30488 ай бұрын
def solve(row, col, board): n = len(board) m = len(board[0]) # Base case: if we've reached the end of the board if col == m: return True # Recursive case: try placing a value in the current cell for value in range(1, 10): # Try values from 1 to 9 board[row][col] = value # Place the value in the current cell if validPlacement(row, col, board): # Check if the placement is valid # If the placement is valid, recursively solve for the next cell if solve(row, col + 1, board): return True # If the placement is not valid or does not lead to a solution, backtrack board[row][col] = 0 # Reset the cell to empty # If no value leads to a solution, return False return False def validPlacement(row, col, board): # Implement the logic to check if placing a value at the given row and column is valid pass # Placeholder, replace with your implementation # Example usage: # Initialize a 9x9 Sudoku board (as a list of lists) board = [ [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0] ] # Start solving from the top-left corner (row=0, col=0) if solve(0, 0, board): print("Solution found:") for row in board: print(row) else: print("No solution exists.") i think theres an error like we need to reset if placement is not valid here i see that its directly outside the fore loop means we reset every cell to 0 once every iteration s are done please corect me if im wrong
@tushargoyal67045 жыл бұрын
this video is one of the best i have ever seen on teaching skills.
@BackToBackSWE5 жыл бұрын
thanks
@tushargoyal38044 жыл бұрын
@@BackToBackSWE I today got placed at Wells Fargo and I am here to say thank you to you. From you, I have learned the most important technique that is how to approach a problem. Thanks again and keep sharing your knowledge
@karthiks94262 жыл бұрын
When KZbin suggested this video for Backtracking, I was wondering why Lewis Hamilton is explaining Backtracking 🤔 😳. But you certainly didn't disappoint. Thanks for the great explanation 👍
@BackToBackSWE2 жыл бұрын
haha! thanks. Hoping to see Lewis back on the f1 track
@BackToBackSWE2 жыл бұрын
Subscribe to our DSA course with a flat 30% discount for some amazing content b2bswe.co/3HhvIlV
@mvmcali69004 жыл бұрын
"I kind of just went for it ..and talked a lot " . That's honestly funny.. nice videos my friend
@BackToBackSWE4 жыл бұрын
yeah lol
@Code4You12 жыл бұрын
2:53 I love that we all think as a first about a double for loop for each coding question :))
@hackerandpainter3 жыл бұрын
Lol "i don't think that video is that good..." nah YOU ARE AMAZING MAN IF I PASS MY INTERVIEW ON FRIDAY A LARGE CREDIT WILL BE TO YOU. Thank you! ❤️
@bokams33853 жыл бұрын
I like ur way of thinking and asking questions during solve any problem
@ronmc16775 ай бұрын
Nice video man. I like your style of teaching, this is the first ever video of yours that I've watched and I like the casual style of teaching. It would be great if you could make videos that emphasize the guiding principle behind solving a problem and then share ways to attack the problem as well, in a direct way. Thanks and Cheers!
@bethlehemdereselegn79004 жыл бұрын
i didn't knw abt backtracking at all and zis helped me on understanding string permutation more. Soo thank you.
@BackToBackSWE4 жыл бұрын
sure
@NganVoooo5 жыл бұрын
Thanks for making these videos! Your videos are always really engaging and really well-thought out. I hope you keep going with this channel; it's really invaluable to the SWE community. I feel this one particularly was really great because it really helps with building the mental model needed to approaching backtracking. You generally do a great job at this in your other videos, but I'm really glad you took the time to dedicate a whole video on the general approach. It's always great to be able to solve problems, but even more important to build the right intuition.
@BackToBackSWE5 жыл бұрын
sure, I try my best....most of the time :)
@yizhangchen74095 жыл бұрын
I love the clarity of your video! Thank you very much!
@BackToBackSWE5 жыл бұрын
sure
@tommyshelby20204 жыл бұрын
Really awesome videos, watched most of your DP's, annoyed my friends sharing them all the links. Hope you & your channel achieve greater success!
@BackToBackSWE4 жыл бұрын
thanks for sharing us, best thing anyone can do to help. And thanks, we are working on it.
@ChaosB7ack2 жыл бұрын
This mental model was great to learn! Thank you for the quality.
@kbarot38864 жыл бұрын
Make the n-queen problem again please. U really helped me understand dynamic programming, thank you so much!
@BackToBackSWE4 жыл бұрын
Yeah I think I can explain it better today vs 1 year ago
@chaplinhuang460 Жыл бұрын
I love you. Thank you so much. The last minute of reflection is all I need for the day. Thank you, thank you, thank you.
@BackToBackSWE Жыл бұрын
Happy Holidays! Really glad to help 🎉 Do you know about the 5 Day Free Mini Course? Check it out here - backtobackswe.com/
@axelalvarenga4477 Жыл бұрын
Thanks for the video. Really helpful for my efforts to pass an algorithms and data structures class in undergrad CS.
@maithreyiprabhu28534 жыл бұрын
Thank you so much for this. Looking forward to seeing more videos regularly. I don't know why I didn't come across this channel sooner.
@BackToBackSWE4 жыл бұрын
welcome
@hetalrachh56654 жыл бұрын
This now my favorite channel for Data structures. Thank you for such amazing videos :)
@BackToBackSWE4 жыл бұрын
sure
@vishalkarki94894 жыл бұрын
try mycodeschool channel
@danavram84374 жыл бұрын
One thing missing from this video is explaining why the time complexity is what it is, what is the space complexity and, most importantly, WHY?
@BackToBackSWE4 жыл бұрын
Yeah
@sophiehall385 жыл бұрын
I don't know whether I told you this before, but your video are reallllllllllly great!
@BackToBackSWE5 жыл бұрын
haha thanks
@jocalvo2 жыл бұрын
That was probably the best explanation of backtracking out there . Thanks a lot!
@BackToBackSWE2 жыл бұрын
Thank you, glad you liked it 😀 Do check out backtobackswe.com/platform/content and please recommend us to your family and friends 😀
@youtv995 жыл бұрын
The content you are creating is valuable. Educational and entertaining and delivered a way that makes it stick in memory. The approach to the topics makes it easy to grasp and remember the base concepts and tool sets which gives the confidence to handle any interview question. Being able to quickly classify the type of problem and the tool set, algorithm and data structure to address it makes all the difference. If you could somehow show how to implement the code on white board would be cool. Also, some sample interview role playing with be great.
@BackToBackSWE5 жыл бұрын
Yeah, I have a video coming out in a little that will address the future of this project.
@antbotboy5 жыл бұрын
Wow, this video really opened a new way of looking at the problems. Thank you and keep making videos!
@BackToBackSWE5 жыл бұрын
sure
@nitinsrivastava14735 жыл бұрын
doing great job man!.... It's just my second video that i watched..... I really have respect for you .
@BackToBackSWE5 жыл бұрын
nice thanks
@LTF-uj1yc4 жыл бұрын
This consolidated my understanding of backtracking, thank you.
@BackToBackSWE4 жыл бұрын
great.
@RiteshSingh-lo9cn5 жыл бұрын
first time on this channel and subscribed it... Awesome way of teaching... Request to everyone: Share this video more nd moe
@BackToBackSWE5 жыл бұрын
ha thanks, we have a course where I'm posting more videos like this, check it out
@christianbejarano62633 жыл бұрын
Best explanation I've found so far. Thank you man
@maheshbanjan8565 жыл бұрын
Your explanation is seriously good. Keep up the videos. Would love to see your channel grow
@BackToBackSWE5 жыл бұрын
thanks, me too
@copindeanalex4 жыл бұрын
Thank you so much, really clarified my doubts about the usefulness of backtracking. My university teacher should be learning from you how to explain algorithms.
@BackToBackSWE4 жыл бұрын
nice
@JiaTanchun Жыл бұрын
I like your content. I appreciate your enthusiasm from your voice and smile.
@BackToBackSWE Жыл бұрын
Thank you! Please enjoy a special code from us - backtobackswe.com/checkout?plan=lifetime-legacy&discount_code=IneluctableConcomitant 🎉
@ТимурБелянин-й3ф8 ай бұрын
Thank you dear man for your clear explanations! Hello from Russia!
@sakhriwissal56072 жыл бұрын
you're just amazing I love how you went for it! keep it up !!!!! your channel is a treasure
@BackToBackSWE2 жыл бұрын
Means a lot
@moody_moolga4 жыл бұрын
You are real! That's all I can say! stay real man!!!
@BackToBackSWE4 жыл бұрын
thx.
@Beeliswahili5 жыл бұрын
Very nicely done. One request. When you screen reference the previous related videos, could you add a link in your intro text along with the other excellent links you provide...I'm reviewing them all in sequence to help me work through these problems and leetcode questions. Your explanations provide great insights and I REALLY appreciate all of the effort you have placed in these discussions. Thank you!
@BackToBackSWE5 жыл бұрын
yeah sure
@pradyooo4 жыл бұрын
Love the effects in the videos, helps us understand
@BackToBackSWE4 жыл бұрын
great
@TacklessNebula33 жыл бұрын
This was great. First time in your channel mate, and you have already earned another subscriber... Keep on making such videos, that'll help us looking at such algorithms from another perspective, and help you learn more as you make them! Thanks!
@gfdtfgf3278 Жыл бұрын
V TV FC hmm
@aayushsharma1452Ай бұрын
Great explanation. Zero BS. Thanks
@BaishaliGhosh135 жыл бұрын
Thank you once again. This was a cool way to think about backtracking problems. I personally feel some of the dp and backtracking questions draw a lot from mathematical induction and the ability to be able to express a question recursively like you said. I will practice a couple and see if I have a better hang of these problems. Thanks a ton for doing such a great job. Love your videos.
@BackToBackSWE5 жыл бұрын
sure
@ll-sz9fl4 жыл бұрын
You could solve the Sudoku with DP, it would be faster: O(n*m), where n and m are the height and width of the grid.
@BackToBackSWE4 жыл бұрын
ok
@tammyhi Жыл бұрын
Thank you for the video! This was really helpful and made it easier for me to understand Backtracking!
@dawitz362Ай бұрын
Thanks for the best explanation. You have got my subscription and like.
@shnerdz5 жыл бұрын
Hey man, recently found your channel and I absolutely love your teaching style. The quality of the videos have been getting better, too. I've been trying to practice more leetcode for interviews and whatnot, but since I've only recently started, I'm struggling quite a bit. When you see a problem that you do not understand or just have no idea how to solve at all, at what point do you give up and look at the answer?
@BackToBackSWE5 жыл бұрын
Thanks, thanks, and it depends greatly. If I know the problem class I'll keep going. But if I am just 100% stumped for 20 minutes, with no leads to start (which that still happens), only then do I look at the answer. And then there are times I look at the answers very quickly, just to get a mass of questions in. Ummm...yeah this really depends.
@mrboyban2 жыл бұрын
Good stuff! It is a pitch my uni 'teacher' is using your material instead of doing his own . I feel that I should be giving you the tuition fee not to the university of York.
@BackToBackSWE2 жыл бұрын
Hahaha!! 😀 Please do recommend us to your family and friends 😀 and do check out backtobackswe.com/platform/content
@asgm13822 жыл бұрын
Excellent video! Thank you for sharing. I love your explanation towards the end and could not agree more.
@BackToBackSWE2 жыл бұрын
Glad you enjoyed it!
@vrushalidesai18073 жыл бұрын
This has been SO helpful. Thank you thank you thank you for breaking it down in a way that makes it super easy to understand!
@brandonnguyenlam Жыл бұрын
Absolutely stellar video and explanation of backtracking. Thank you.
@BackToBackSWE Жыл бұрын
Happy Holidays! Really glad to help 🎉 Do you know about the 5 Day Free Mini Course? Check it out here - backtobackswe.com/
@ANoleJoke5 жыл бұрын
13:13 Gold.
@BackToBackSWE5 жыл бұрын
👀👀👀
@LombaxPieboy163 жыл бұрын
This video is great! Very well explained, and I loved the editing :) Awesome job dude!
@giteshkhanna26333 жыл бұрын
It's a really good brief! Thanks for the video !
@RV-kl2wl2 ай бұрын
Extremely good explanation.
@kevinjaypatel3 жыл бұрын
Love your videos man, you're a real one!
@FitnessChaos3 жыл бұрын
Nice breakdown generally on how to think about a solving problem.
@vipulkrishna195 жыл бұрын
Loved your teaching style.. 😍 from india
@BackToBackSWE5 жыл бұрын
wassup
@Kee0392 жыл бұрын
Pls post video for unique path III (LC 980). There is no good explanation on this problem anywhere on youtube.
@vasukhungar25175 жыл бұрын
Hey Ben , your explanation is awesome, can u please explain optimal game strategy question. From recursion to DP.
@BackToBackSWE5 жыл бұрын
yeah, I may throw that into this site: twitter.com/thebigoguide
Back To Back SWE Your determination to save those people suffer from the tech interviews!
@shubhampasari71235 жыл бұрын
You have remarkable editing skills!
@BackToBackSWE5 жыл бұрын
thanks
@ericli55492 жыл бұрын
Thank you for explaining this so well. Crystal clear.
@BackToBackSWE2 жыл бұрын
Thank you, glad you liked it 😀 Do check out backtobackswe.com/platform/content and please recommend us to your family and friends 😀
@kunalsangtiani65343 жыл бұрын
You are a greatttttt teacher , Thankyou so much
@hope42935 жыл бұрын
Thank you! All your explanation help my exam!
@BackToBackSWE5 жыл бұрын
sure
@hornsbeef10 ай бұрын
You good sir are my hero!
@Rhythmswithruby4 жыл бұрын
What's the difference between a DFS and Backtracking problem?
@BackToBackSWE4 жыл бұрын
DFS is a search methodology & backtracking is more of a description of an algorithmic behaviour.
@samiaghezal3 жыл бұрын
the title is general, but all the explanation is reliant on a very specific example. What if I don't know sudoko?
@thankgoditsover4 жыл бұрын
Appreciate your work, man! Thank you!
@BackToBackSWE4 жыл бұрын
sure
@YasserSinjab4 жыл бұрын
you deserve a super LIKE !
@BackToBackSWE4 жыл бұрын
thanks
@h0td0g3 ай бұрын
is there a precursor video to this? i feel like i understood nothing from your video.
@pranayreddy2190 Жыл бұрын
Is that you, Lewis Hamilton?
@lokeshisrani88274 жыл бұрын
I am creating a sudoku grid filler (from empty cells) and using this approach. But after being able to fill two three rows with all constraints (of rows, columns and blocks) the program doesn't run. With any one constraint it works, but with all it goes whacky. Any help?
@BackToBackSWE4 жыл бұрын
I can't debug your code
@lokeshisrani88274 жыл бұрын
@@BackToBackSWE Yup. Totally get that. :) Thanks anyway.
@MarcStevens995 жыл бұрын
I'm wondering if you could store the decision space in an array or hashset. So each stack frame would only have to loop through a _maximum_ of N choices, but a minimum of 1 choice.
@BackToBackSWE5 жыл бұрын
could you elaborate?
@MarcStevens995 жыл бұрын
If you're at cell (3,2) - 3rd row, 2nd column. You already know placements (0,2), (1,2), (2,2) and similarly (3,0), (3,1). So you need not search for the decision space that is already allocated to those cells. This optimisation would take up a lot of space though - so it may not be worth it.
@BladeAurora4 жыл бұрын
Thanks man, this help me solve leetcode 79 word search