No video

Permutations - Leetcode 46 - Recursive Backtracking (Python)

  Рет қаралды 6,004

Greg Hogg

Greg Hogg

Күн бұрын

Пікірлер: 27
@GregHogg
@GregHogg Ай бұрын
Master Data Structures & Algorithms For FREE at AlgoMap.io!
@shreehari2589
@shreehari2589 4 ай бұрын
Greg you have natural talent in teaching, kindly don’t stop making videos
@GregHogg
@GregHogg 4 ай бұрын
Awe that's so sweet. Probably just practice as I've been learning and teaching for awhile now. I really appreciate it!! 😊
@dabian1916
@dabian1916 Ай бұрын
so much better than neetcode
@GabriellBP1
@GabriellBP1 Ай бұрын
have to agree on that one
@shubhamdas9489
@shubhamdas9489 Сағат бұрын
Yeah
@AbhishekYadav-yw8kv
@AbhishekYadav-yw8kv 11 күн бұрын
such an elegant explanation. Thanks Greg!
@saurabh-11a
@saurabh-11a 27 күн бұрын
Hi Greg, I could not understand how the pop is working here, once we have the first solution, I dont understand how pop is happening twice in the for loop.
@stanleyching123
@stanleyching123 25 күн бұрын
Leaving a comment here as I want to also know
@SBManukrishna-jz6ud
@SBManukrishna-jz6ud 8 күн бұрын
Hello Saurabh, Here is how pop() does the work here.After we append the first solution to ans,the control gets back to the "sol.pop()"line and we pop 3 from sol since its the last element. At this stage note that we are in the last iteration of for loop as well since x =3. So we don't have to execute anything further with backtrack() when x=3. So now we return back the sol which is [1,2] to backtrack() when x =2. Now the next line is sol.pop().So we pop 2 from sol and hence sol becomes [1].but here is the catch... now x=2 and the loop has 1 more interation for x=3 so we check if 3 is in solution and add it into sol and sol becomes [1,3], now we call backtrack() and we compare the len of sol to n which is not equal to 3 so we start the for loop afresh once again and check if 1 is in sol. Yes 1 is in sol=[1,3],but in next iteration when x=2 since 2 is not in sol, we add it to sol and add it to ans. This is how we formulate the 2nd solution. Hope you can figure out the flow for remaining solutions and hope this helped😊
@Zippo_1234
@Zippo_1234 10 күн бұрын
This was excellent. Thank you
@jz77096
@jz77096 20 күн бұрын
I think this problem is purely a test of how to code it concisely. Leetcoding to land a Meta/Google position. Gotta use code that interviewers can read... so found 3 solutions: Dupes Insertion into a growing temp linkedList Rotations Took me a couple hours to solve on my own, giving up, then looking it up.
@christianjt7018
@christianjt7018 28 күн бұрын
I learned backtracking thanks to you, thanks Greg!
@GregHogg
@GregHogg 28 күн бұрын
Amazing 😍😍
@sabaokangan
@sabaokangan 4 ай бұрын
Beautiful teaching
@GregHogg
@GregHogg 4 ай бұрын
Thanks a ton!!!
@HemanthKumar-vl9oh
@HemanthKumar-vl9oh Ай бұрын
Woow ! You made look so simple . Good job. Keep doing such videos
@GregHogg
@GregHogg Ай бұрын
Thank you!
@rishabkalluri662
@rishabkalluri662 Ай бұрын
Isn't the time complexity N! * n? , checking if x in sol is n
@rishabkalluri662
@rishabkalluri662 Ай бұрын
or copying solution before you add it is n
@aswination
@aswination 3 ай бұрын
Excellent video! How would the code change if there are duplicate numbers in the array?
@GregHogg
@GregHogg 3 ай бұрын
Thank you! And there's actually a problem for that, might cover it at some point :)
@user-hu9nu8xu5g
@user-hu9nu8xu5g Ай бұрын
bro what is if x not in sol, can you explain that I don't understand bro
@GregHogg
@GregHogg Ай бұрын
If we've already used the number, we don't want to use it again
@isako1234
@isako1234 Ай бұрын
its O(n! * n), because of the line: if x not in sol
@yunusemreozvarlik2906
@yunusemreozvarlik2906 Ай бұрын
Same for the space complexity. It should be O(n! * n)
@vroomerlifts
@vroomerlifts 2 ай бұрын
hell yeah
Combinations - Leetcode 77 - Recursive Backtracking (Python)
7:56
LeetCode was HARD until I Learned these 15 Patterns
13:00
Ashish Pratap Singh
Рет қаралды 247 М.
Blue Food VS Red Food Emoji Mukbang
00:33
MOOMOO STUDIO [무무 스튜디오]
Рет қаралды 32 МЛН
나랑 아빠가 아이스크림 먹을 때
00:15
진영민yeongmin
Рет қаралды 14 МЛН
Nurse's Mission: Bringing Joy to Young Lives #shorts
00:17
Fabiosa Stories
Рет қаралды 14 МЛН
Oh No! My Doll Fell In The Dirt🤧💩
00:17
ToolTastic
Рет қаралды 13 МЛН
Subsets - Leetcode 78 - Recursive Backtracking (Python)
11:51
Leetcode 46. Permutations : Introduction to backtracking
10:06
ComputerBread
Рет қаралды 94 М.
How Fast can Python Parse 1 Billion Rows of Data?
16:31
Doug Mercer
Рет қаралды 216 М.
Please Master These 10 Python Functions…
22:17
Tech With Tim
Рет қаралды 149 М.
Number of Islands - Leetcode 200 - Graphs (Python)
11:01
Greg Hogg
Рет қаралды 5 М.
I've been using Redis wrong this whole time...
20:53
Dreams of Code
Рет қаралды 356 М.
Permutations - Leetcode 46 - Python
11:58
NeetCodeIO
Рет қаралды 18 М.
Blue Food VS Red Food Emoji Mukbang
00:33
MOOMOO STUDIO [무무 스튜디오]
Рет қаралды 32 МЛН