Skip to content

Instantly share code, notes, and snippets.

@mvallebr
Created April 2, 2025 22:11
Show Gist options
  • Select an option

  • Save mvallebr/231ab15effafdb756df2a1ee08d58b64 to your computer and use it in GitHub Desktop.

Select an option

Save mvallebr/231ab15effafdb756df2a1ee08d58b64 to your computer and use it in GitHub Desktop.
from typing import List
MODULO_BASE = 10**9 + 7
def _num_combinations(m: int):
if m <= 0:
return 0
half = m // 2
return 2**half
def infected_combination(n: int, infectedHouses: List[int]) -> int:
if len(infectedHouses) == 0:
return 0
total = 0
if infectedHouses[0] > 1:
total += 1
if infectedHouses[-1] < n:
total += 1
for a, b in zip(infectedHouses, infectedHouses[1:]):
total += _num_combinations(b - a - 1)
return total % MODULO_BASE
print(infected_combination(12, [2, 10]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment