We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2d4fe0d commit 413b1d2Copy full SHA for 413b1d2
solution/0600-0699/0624.Maximum Distance in Arrays/Solution.js
@@ -0,0 +1,19 @@
1
+/**
2
+ * @param {number[][]} arrays
3
+ * @return {number}
4
+ */
5
+var maxDistance = function(arrays) {
6
+ let minVal = arrays[0][0];
7
+ let maxVal = arrays[0][arrays[0].length - 1];
8
+ let maxDist = 0;
9
+
10
+ for (let i = 1; i < arrays.length; i++) {
11
+ const currentMin = arrays[i][0];
12
+ const currentMax = arrays[i][arrays[i].length - 1];
13
+ maxDist = Math.max(maxDist, Math.abs(currentMax - minVal), Math.abs(maxVal - currentMin));
14
+ minVal = Math.min(minVal, currentMin);
15
+ maxVal = Math.max(maxVal, currentMax);
16
+ }
17
18
+ return maxDist;
19
+};
0 commit comments