Since the array is sorted the farthest points will be a [ i ] and a [ k ] ;
$ mostDistantDistance = $ arr [ $ k ] - $ arr [ $ i ] ; if ( $ mostDistantDistance <= $ L ) { $ ways ++ ; } } } } return $ ways ; }