Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
no variants, just logic solution in Clear category for Garland by freeman_lex
def illuminate_all(lights: list[int]) -> int:
longest = [-1] * len(lights)
for ind, br in enumerate(lights):
for j in range(max(0, ind - br), min(len(lights), ind + br + 1)):
longest[j] = max(longest[j], ind + br - j + 1)
ind = counter = 0
while ind < len(lights):
counter += 1
ind += longest[ind]
return counter
print("Example:")
print(illuminate_all([0, 0]))
# These "asserts" are used for self-checking
assert illuminate_all([0, 0]) == 2
assert illuminate_all([2, 3, 3, 2]) == 1
assert illuminate_all([1, 0, 1, 0]) == 2
print("The mission is done! Click 'Check Solution' to earn rewards!")
Aug. 2, 2023
Comments: