Last active
June 20, 2020 18:54
-
-
Save pyrofolium/65fb481d647666eadc9a4a257ad15eb0 to your computer and use it in GitHub Desktop.
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
def mult_list(x: List[int], start: int, end: int, memo: Optional[Dict[Tuple[int, int], int]] = None) -> int: | |
memo = {} if memo is None else memo | |
if (start, end) in memo: | |
return memo[(start, end)] | |
if start >= end: | |
memo[(start, end)] = 1 | |
else: | |
memo[(start, end)] = x[0] * mult_list(x, start + 1, end, memo) | |
return memo[(start, end)] | |
def get_mults(x: List[int]) -> List[int]: | |
memo = {} | |
return [mult_list(x, 0, i, memo) * mult_list(x, i + 1, len(x)), memo) for i in range(len(x))] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment