MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / dp

Function dp

digit_dp.py:14–19  ·  view source on GitHub ↗
(i, isPrefix, isBigger)

Source from the content-addressed store, hash-verified

12
13 @functools.lru_cache(None)
14 def dp(i, isPrefix, isBigger):
15 if i == len(N):
16 return not isBigger
17 if not isPrefix and not isBigger:
18 return 1 + len(D) * dp(i + 1, False, False)
19 return 1 + sum(dp(i + 1, isPrefix and d == N[i], isBigger or (isPrefix and d > N[i])) for d in D)
20
21 return dp(0, True, False) - 1

Callers 1

atMostNGivenDigitSetFunction · 0.85

Calls 1

sumFunction · 0.85

Tested by

no test coverage detected