Letter Combinations of a Phone Number - Leetcode 17 - Recursive Backtracking (Python)

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


Please check my playlists for free DSA problem solutions:

My Favorite Courses:

Data Structures & Algorithms:

Python:

Web Dev / Full Stack:

Cloud Development:

Game Development:

SQL & Data Science:

Machine Learning & AI:
Рекомендации по теме
Комментарии
Автор

Master Data Structures & Algorithms For FREE at AlgoMap.io!

GregHogg
Автор

bro I don't undrstand but bro thank you I'll watch this playlist again

GarouNguyen
Автор

wouldn't time complexity technically be O(4^n*n) given for each combination you are doing a join operation which creates a new string by combining n characters, which takes O(n) time

codeaucafe
Автор

def letterCombinations(digits: str) -> list[str]:

mapping = {
'2': 'abc', '3': 'def',
'4': 'ghi', '5': 'jkl', '6': 'mno',
'7': 'pqrs', '8': 'tuv', '9': 'wxyz'
}
n = len(digits)

ans = []

def backtrack(i, sol):
if n and len(sol) == n:
ans.append(sol)
return
if i == n:
return
for x in mapping[digits[i]]:
backtrack(i+1, sol+x)

backtrack(0, '')
return ans

nivethithanmanivannan
Автор

Hi, I don't understand the pop. if I append ['a'] then go on to append ['a', 'd'], ['a', 'e'], ['a', 'f'] then when I pop how do I not pop ['a', 'f'] since it was the last thing added?

Alex-fedr
Автор

just wanted to flex that I managed to solve this one without the video after doing the previous ones and I must say few things feel better than this

kubs
Автор

Space complexity here I think is wrong. Should be 4^n not just n.

testingaccount-xb
Автор

bro i watch playlist of you about refursion but i still don't understand jus tundrstand 60% of it

GarouNguyen
join shbcf.ru