Skip to content

Instantly share code, notes, and snippets.

@pyrofolium
Last active June 20, 2020 18:54
Show Gist options
  • Save pyrofolium/65fb481d647666eadc9a4a257ad15eb0 to your computer and use it in GitHub Desktop.
Save pyrofolium/65fb481d647666eadc9a4a257ad15eb0 to your computer and use it in GitHub Desktop.
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