Javascript Solution


  • 0
    R
    function maxDistance(arrays) {
      let result = 0;
      let prevMax = arrays[0][arrays[0].length - 1];
      let prevMin = arrays[0][0];
      
      for (let i = 1; i < arrays.length; i++) {
        result = Math.max(result, Math.abs(arrays[i][0] - prevMax));
        result = Math.max(result, Math.abs(arrays[i][arrays[i].length - 1] - prevMin));
        prevMax = Math.max(prevMax, arrays[i][arrays[i].length - 1]);
        prevMin = Math.min(prevMin, arrays[i][0]);
      }
     
      return result;
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.