Thank you for explaining permutations to me! It seems so simple, but it's been the hardest thing to understand. After a long day of procrastinating and not really feeling like coding, I'm glad I watched this! I learned something new and understand this problem which I have been running my wheels on for a WHILE now! thank you!
I dont know how someone could dislike this, kinda crazy. Your videos are amazing. Nice to listen to and easy to understand, keep up the great work! You are helping so many of us!
I found your channel recently and to be honest it's one of the best when it comes to solving and explaining the solutions. I really enjoying it even though python is not my thing.
How does [ 3, 2 ] become in our scope? With nums[:x] + nums[x + 1:] I get how we get [2, 3], but I just can't visualize how we can get [3, 2], [3,1], etc.. (basically anywhere where the permutation is in an order that is different than that of the input array.
Thank you sooooooo much for this video! It’s really helpful. I felt so stupid in class as I didn’t understand it. but your explanation was so clear 🙏 a million thanks yous for uploading this video
Bro u r awesome ! I'm when I first try to solve this question I'm like blank I can't find a approach and now I'm laughing on myself 😂 bro u r awesome 🔥🔥
Thanks for the video! Could you go over the time and space complexity of your solution? I think the space complexity is O(N^2) because the stack will reach a depth of N, and each call contains a nums and path variables which can each be of size N. I think the time complexity is (N!*N) because there will N! calls and each call requires creating the nums and path variables, which each can be up to size N
the sc is O(n^2*n!) because we call the path(O(n)) and nums(O(n)) (" n! times "and we store path and nums everytime calling the recursive function (backtracking)
so after reaching [1,2,3] then we would go back a step getting us to the second position and we try the remaining combination which in this case would be [1,3,2] after this we tried all combination for the second and third spot so we go back to the very first spot giving us [2,1,3] and so and until we get all combinations.
Hi Sai thank you so much for the video! This really helped me make my solution fast. I do have a question for you, I was initially using copy.deepcopy to create a new copy of the "nums" array and a new copy of the "path" array and passing it into each recursive call (after the necessary modifications, like removing the current element from nums). However that solution was extremely slow. I see that you do the exact same thing but with nums[:x]+nums[x+1:] && path+[nums[x]] respectively ~ can you tell me why this solution is so much faster than what I was doing?
Thank you so much for the video!
Here's your code, just a bit cleaner:
class Solution:
def permute(self, nums: list[int]) -> list[list[int]]:
res = []
def backtrack(nums, path):
if not nums:
res.append(path)
for i in range(len(nums)):
backtrack(nums[:i]+nums[i+1:], path + [nums[i]])
backtrack(nums, [])
return res
Thank you for explaining permutations to me! It seems so simple, but it's been the hardest thing to understand. After a long day of procrastinating and not really feeling like coding, I'm glad I watched this! I learned something new and understand this problem which I have been running my wheels on for a WHILE now! thank you!
way better explained and coded than any other video I could find, thank you
I dont know how someone could dislike this, kinda crazy. Your videos are amazing. Nice to listen to and easy to understand, keep up the great work! You are helping so many of us!
Thanks a lot I'm glad it helps :)
I found your channel recently and to be honest it's one of the best when it comes to solving and explaining the solutions. I really enjoying it even though python is not my thing.
Thanks you I'm glad these vides are helpful!!
This is one of the simplest and most comprehensive solutions i've ever come across pertaining to this problem . Thank you
Thank you, this is the first explanation that actually made sense to me!
omg awesome bruh, you are the best since you are the only one treat us like *we know nothing* 😂
Excellent clarity of communication
Glad it helped
Your vids are so helpful that I find myself specifically picking mediums/hards that you've covered!
I'm glad the videos are helping!!
very nice solution ~ the other solutions i saw for permutations were bending my mind, but this one is super clear. thx
How does [ 3, 2 ] become in our scope? With nums[:x] + nums[x + 1:] I get how we get [2, 3], but I just can't visualize how we can get [3, 2], [3,1], etc.. (basically anywhere where the permutation is in an order that is different than that of the input array.
Thank you sooooooo much for this video! It’s really helpful. I felt so stupid in class as I didn’t understand it. but your explanation was so clear 🙏 a million thanks yous for uploading this video
amazing crystal clear solution....thankyou for explanation
Great explanation!
Great Explanation🙏
Your explanation is very clear and explicit!
Glad it was helpful!
Wow just awesome!!! This channel is gonna blow up someday :)
Glad it helped!!
Bro u r awesome ! I'm when I first try to solve this question I'm like blank I can't find a approach and now I'm laughing on myself 😂 bro u r awesome 🔥🔥
Happy to help and thank you!!
thank you for such an amazing explanation!!!!
amazing video 😭
Thanks for the video. Could you explain how the recursion in the last function makes the nums[] empty? I am always very confused about recursion.
Thanks...That was so helpful
great solution!
Can you please tell a solution using this approach only but not using slicing. How can this be implemented using Append and Pop
Thanks for the video! Could you go over the time and space complexity of your solution? I think the space complexity is O(N^2) because the stack will reach a depth of N, and each call contains a nums and path variables which can each be of size N. I think the time complexity is (N!*N) because there will N! calls and each call requires creating the nums and path variables, which each can be up to size N
Thank you for explaining the time and space complexity!
the sc is O(n^2*n!) because we call the path(O(n)) and nums(O(n)) (" n! times "and we store path and nums everytime calling the recursive function (backtracking)
Isn't the time complexity n^2 * n! because there will be n! calls and each call iterates over nums and then create nums so n^2 ?
How to get p permutations of n numbers? Like 5 permutations from 10 random numbers
Perfect! Thanks, Sai.
Thank you! Well explained.
Great Explanation!!!!
Glad it was helpful!
I love watching your video and please come on!
Thank you! I'm not too sure what you mean by the second part.
@@saianishmalla2646 oh sorry, I mean please keep on updating new videos!
haha yes ofc :)
Is it possible to generate all possible differences between a pair of numbers in a list: e.g., lst = [1, 2, 3, 4]?
Path=[1,2,3] then it reaches a base case and path will be append to the result list.What will be next step?
so after reaching [1,2,3] then we would go back a step getting us to the second position and we try the remaining combination which in this case would be [1,3,2] after this we tried all combination for the second and third spot so we go back to the very first spot giving us [2,1,3] and so and until we get all combinations.
@@saianishmalla2646 thank you😌
Thx for the video, is the solution iterative or recursive?
I want support in python can you help me?
Thanks for the explanation
glad it helped!
Hi Sai thank you so much for the video! This really helped me make my solution fast. I do have a question for you, I was initially using copy.deepcopy to create a new copy of the "nums" array and a new copy of the "path" array and passing it into each recursive call (after the necessary modifications, like removing the current element from nums). However that solution was extremely slow. I see that you do the exact same thing but with nums[:x]+nums[x+1:] && path+[nums[x]] respectively ~ can you tell me why this solution is so much faster than what I was doing?
Soooo good
Thanks!
This solution as is doesn't work. Copy and paste it to see. Structure of result etc is broken
try this on n=10^6 lol