Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
dynamic programming (pure FP) solution in Clear category for Workout by juestr
from functools import reduce
from typing import List
def workout(sessions: List[int], additional: int) -> int:
def add_step(difficulties: List[int], step: int) -> List[int]:
step_divided = [(step + adds) // (adds + 1) for adds in range(additional + 1)]
return [min(max(difficulties[adds - adds_here], step_divided[adds_here])
for adds_here in range(adds + 1))
for adds in range(additional + 1)]
steps = [b - a for a, b in zip(sessions, sessions[1:])]
difficulties0 = [0] * (additional + 1)
return reduce(add_step, steps, difficulties0)[-1]
May 15, 2020