1
var minSpeedOnTime = function (dist, hour) {7
while (left <= right) {8
//We need to return the minimum positive integer speed (in kilometers per hour) that all the trains must travel. So speed will always be an integer ranging from 1 to 10000000 as per the question description.9
speed = left + Math.floor((right - left) / 2);11
for (let i = 0; i < dist.length - 1; i++) {12
sum += Math.ceil(dist[i] / speed);14
sum += dist[dist.length - 1] / speed; //For the last train we need not to do Math.ceil16
//sum(time taken is less than the required time, so it can be our answer, but we will keep looking for the another smaller speed until left<=right)