We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
This problem is shit because of the test cases. You don't need memoization or dynamic programming. It is quite simple with tail recursion
`python
def passwordCracker(passwords, login, res=''):
if login == '':
return res
match = next((p for p in passwords if login[0:len(p)] == p), None)
if match is None:
return 'WRONG PASSWORD'
if match == login:
return res + match
# Does not use up stack space since we use a trampoline
return passwordCracker, (passwords, login[len(match):], res + match + ' ')
# Trampoline to simulate tail calls in Python
result, args = passwordCracker, (passwords, loginAttempt)
while callable(result):
r = passwordCracker(*args)
try:
result, args = r
except:
result = r
`
However for many test cases there are multiple solutions and IMO, this problem should just be removed from this site
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Password Cracker
You are viewing a single comment's thread. Return to all comments →
This problem is shit because of the test cases. You don't need memoization or dynamic programming. It is quite simple with tail recursion
`python def passwordCracker(passwords, login, res=''): if login == '': return res match = next((p for p in passwords if login[0:len(p)] == p), None)
# Trampoline to simulate tail calls in Python result, args = passwordCracker, (passwords, loginAttempt) while callable(result): r = passwordCracker(*args) try: result, args = r except: result = r `