Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Recursion solution in Clear category for Fast Train by lolucky
var fastTrain=(R,f=(i,d,l,e,s) => {
d-=s
if(s>l)return
if(d<=0){
i++
if(s>e&&d<0)return
if(!R[i])return d==0&&s>1?NaN:1
l=e
d+=R[i][0]
e=R[i+1]?.[1]??1}
var t=f(i,d,l,e,s+1)||f(i,d,l,e,s)||f(i,d,l,e,s-1)
return t+!!t}) => f(-1,0,1,R[0][1],0)-1
Nov. 17, 2020
Comments: