Interview Bootcamp
Ask Author
Back to course home

0% completed

Vote For New Content
Mohammed Dh Abbas
My solution . This is more elegant . Mastering recursion allows you to do more during the interviews!

Mohammed Dh Abbas

Sep 26, 2024

class Solution: def findLetterCaseStringPermutations(self, text): def backtrack(word, result, seen, index): result.append(word[:]) for i in range(index, len(word)): # loop through each character in the text char = word[i] if i not in seen and not char.isnumeric(): # if the character is not a number and have no been seen seen.add(i) new_word = word[:i] + char.swapcase() + word[i + 1:] backtrack(new_word, result, seen, i) # recurse back seen.remove(i) result = [] backtrack(text, result, set(), 0) return result

1

0

Comments
Comments
L
lejafilip 9 months ago

Yea this is the best pattern for this kind of problems.