Skip to content

Instantly share code, notes, and snippets.

@Julisam
Created May 30, 2021 14:47
Show Gist options
  • Save Julisam/68cc75602be4c90ee4ff1cee52f105c1 to your computer and use it in GitHub Desktop.
Save Julisam/68cc75602be4c90ee4ff1cee52f105c1 to your computer and use it in GitHub Desktop.
AlgorithmFriday_Week8
# First define the list of chars for all digits
num_dict = {'2': ['a', 'b', 'c'],
'3': ['d', 'e', 'f'],
'4': ['g', 'h', 'i'],
'5': ['j', 'k', 'l'],
'6': ['m', 'n', 'o'],
'7': ['p', 'q', 'r', 's'],
'8': ['t', 'u', 'v'],
'9': ['w', 'x', 'y', 'z'],
# just incase 0 and 1 is part of input, we can safely skip
'0': [''], '1': [''],}
# using a recursive approach
def all_combinations(num):
if num==None: return []
try:
num = str(num)
if len(num)==0: return []
if len(num)==1: return num_map[num]
# function that returns comb of only 2 digits
def comb_2(prev, next): return [x+y for x in prev for y in next]
prev = num_dict[num[0]]
for i in num[1:]:
# print(prev)
prev = comb_2(prev, num_dict[i])
return prev
except:
return []
all_combinations(23)
@meekg33k
Copy link

meekg33k commented Jun 4, 2021

Hello @Julisam, congratulations 🎉 your solution has been selected as one of the winning solutions in Week 8 of #AlgorithmFridays.

Your solution is clean, readable and passed the tests. It's nice to see an iterative approach for solving this problem. What do you think the time complexity of your solution is?

Out of the many winning solutions, only 3 will be selected for the $20 prize in a raffle draw. The raffle draw will hold today, Friday June 4 at 3.00pm WAT (7.00 am PST)

If you are interested in being a part of the raffle draw, please send me a DM on Twitter @meekg33k so I can share the event invite with you.

NB: Only solutions of participants who indicated interest in the raffle draw will be considered.

Thanks once again for participating and see you later today for Week 9 of #AlgorithmFridays.

@Julisam
Copy link
Author

Julisam commented Jun 4, 2021

Thank you @meekg33k.
I'm so excited

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment