Permutations - Leetcode 46 - Python

preview_player
Показать описание


0:00 - Read the problem
0:30 - Drawing Explanation
6:08 - Coding Recursive
9:35 - Coding Iterative

leetcode 46

#neetcode #leetcode #python
Рекомендации по теме
Комментарии
Автор

This is a way better explanation than the old video. I went months with this problem unsolved because I just couldn't understand, but this explanation helped me tremendously. Thanks!

riddle-master-ruben
Автор

i think the backtracking solution with decision tree is more intuitive. For each recursion call, you can store the number that has already added to the Answer list into the HashSet, and for each recursion call you can skip the number that already in the HashSet

function permute(nums: number[]): number[][] {
const result = []
const dfs = (set: Set<number>, pm: number[]): void => {
if (pm.length === nums.length) {
result.push([...pm])
return
}
for (let i = 0; i < nums.length; i++) {
if (set.has(nums[i])) {
continue
}
pm.push(nums[i])
set.add(nums[i])
dfs(set, pm)
pm.pop()
set.delete(nums[i])
}
}
dfs(new Set(), [])
return result
}

hasferrr
Автор

Thank you neetcode for again working on this problem :)

bandarupawankumar
Автор

Swapping indices method for this question is probably more clear and you should also review Longest Palindromic Substring question. Solutions in the other questions are quite optimal.
Thanks a lot!

AVGVSTVSivlivs
Автор

@NeetcodeIO PLS add a functionality on your site to not show the topics for the questions. want to do them in order without knowing the topic. thanks

johnveracruz
Автор

Ok, this one's really the first problem in neetcode150 that is actually VERY easy to understand the goal but I personally find it extremely hard to implement

logn-xe
Автор

hey also do video for cherry pickup 1 and bst to sorted DLL

vungrbk
Автор

I live in Russia, a new day has not yet begun, and you are already solving a new problem)

Gomeroff
Автор

I actually just solved the problem yesterday lmao

kanjurer
Автор

Is it possible for you to have some sort of poll or something where we could ask for a video solution of a leetcode problem which you haven't already solved. Because there are quite a few problems which don't have a proper solution on YouTube and God knows when they will appear as POTD.

mukeshrawat