Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 12eba78

Browse files
Time: 1390 ms (22.99%), Space: 42.5 MB (51.44%) - LeetHub
1 parent 37f1f32 commit 12eba78

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution:
2+
def maxDistance(self, arrays: List[List[int]]) -> int:
3+
# Initialize the global minimum and maximum with the first array's elements
4+
min_val = arrays[0][0]
5+
max_val = arrays[0][-1]
6+
7+
max_distance = 0
8+
9+
# Traverse from the second array onwards
10+
for i in range(1, len(arrays)):
11+
# Current array's minimum and maximum
12+
curr_min = arrays[i][0]
13+
curr_max = arrays[i][-1]
14+
15+
# Calculate possible maximum distance using the current array's min and max
16+
max_distance = max(max_distance, abs(curr_max - min_val), abs(max_val - curr_min))
17+
18+
# Update the global minimum and maximum
19+
min_val = min(min_val, curr_min)
20+
max_val = max(max_val, curr_max)
21+
22+
return max_distance

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /