Skip to content

Instantly share code, notes, and snippets.

@jeb2239
Created November 4, 2020 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeb2239/8f7fe22e54cdf6584e5bbce12275e847 to your computer and use it in GitHub Desktop.
Save jeb2239/8f7fe22e54cdf6584e5bbce12275e847 to your computer and use it in GitHub Desktop.
mehdi
#!/bin/python3
import math
import os
import random
import re
import sys
import functools
#
# Complete the 'passwordCracker' function below.
#
# The function is expected to return a STRING.
# The function accepts following parameters:
# 1. STRING_ARRAY passwords
# 2. STRING loginAttempt
#
def passwordCracker(passwords, loginAttempt):
# Write your code here
pwords = set(passwords)
uniqlens = list(set(map(len,passwords)))
uniqlens.sort()
# print(uniqlens)
res=[]
end=len(loginAttempt)
sys.setrecursionlimit(2000)
@functools.lru_cache(None)
def breakString(start):
if start == end:
return True
else:
for i in uniqlens:
nextLoginWord=loginAttempt[start:start+i]
nextLoginAttempt=loginAttempt[start+i:]
# print(nextLoginWord)
if nextLoginWord in pwords:
res.append(nextLoginWord)
if breakString(start+len(nextLoginWord)):
return True
else:
res.pop()
return False
breakString(0)
if len(res)==0:
return "WRONG PASSWORD"
return ' '.join(res)
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input().strip())
for t_itr in range(t):
n = int(input().strip())
passwords = input().rstrip().split()
loginAttempt = input()
result = passwordCracker(passwords, loginAttempt)
fptr.write(result + '\n')
fptr.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment