Created
December 14, 2020 20:23
-
-
Save muratatak77/13cc180b921874e40ca5343984e422ff to your computer and use it in GitHub Desktop.
DP_Mock_Interview Question
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
football | |
each play can lead 2,3 or 7 points. | |
if we are given some score of p find out 2,3 and 7 | |
how many diff perm | |
p = 7 | |
perm count = 4 | |
7 | |
2+3+2 | |
3+2+2 | |
2+2+3 | |
--------- | |
2 3 7 | |
2 3 7 2 3 7 (7) | |
3 7 2 3 2 3 x x | |
(7) x (7) x (7) x | |
''' | |
def overall(nums, target): | |
if len(nums) > 5: | |
return 0 | |
hset = set() | |
nums.sort() | |
n = len(nums) | |
count = 0 | |
def helper(num,remain,slate): | |
nonlocal count | |
if remain == 0: | |
if not str(slate[:]) in hset: | |
count += 1 | |
return | |
elif remain < 0: | |
return | |
else: | |
for num2 in nums: | |
if str(slate[:]) in hset: | |
continue | |
slate.append(num2) | |
helper(num2,remain - num2, slate) | |
hset.add(str(slate[:])) | |
slate.pop() | |
for num in nums: | |
helper(num,target,[]) | |
return count | |
points = [2,3,7] | |
target = 7 | |
res = overall(points, target) | |
print("res : ", res) | |
''' | |
T(N) = O(N.N!) | |
''' |
Author
muratatak77
commented
Dec 14, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment