Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Evenly Spaced Trees by PythonLearner
from typing import List
def evenly_spaced_trees(trees: List[int]) -> int:
trees_number = len(trees)
distance = trees[-1]-trees[0]
intervals = [right-left for left, right in zip(trees[:-1], trees[1:])]
min_interval = min(intervals)
while min_interval > 0 and any(interval%min_interval != 0 for interval in intervals):
min_interval -= 1
return distance//min_interval+1-trees_number
if __name__ == '__main__':
print("Example:")
print(evenly_spaced_trees([0, 2, 6]))
assert evenly_spaced_trees([0, 2, 6]) == 1, 'add 1'
assert evenly_spaced_trees([1, 3, 6]) == 3, 'add 3'
assert evenly_spaced_trees([0, 2, 4]) == 0, 'no add'
print("Coding complete? Click 'Check' to earn cool rewards!")
April 19, 2019
Comments: