MountainRangs algorithm implementation