You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Time: O(k^n), each level of recusive stack at most of k. Space: O(k+n), recursive stack at most depth of n.
classSolution:
defdistributeCookies(self, cookies: List[int], k: int) ->int:
defdfs(i):
nonlocalresifi>=len(cookies):
curmax=max(acc)
res=min(res, curmax)
return# cut the recursionifmax(acc) >=res:
return# for a bag of cookie we have k choices (children) to distribute.forjinrange(k):
acc[j] +=cookies[i]
dfs(i+1)
acc[j] -=cookies[i]
res=math.infacc= [0] *kdfs(0)
returnres
The text was updated successfully, but these errors were encountered:
Time: O(k^n), each level of recusive stack at most of k.
Space: O(k+n), recursive stack at most depth of n.
The text was updated successfully, but these errors were encountered: