Ctrl K

Widest Gap Across Lists

Medium
You are given lists, an array of lists, each sorted in non-decreasing order. Pick two numbers from two **different** lists, one from each. Return the largest possible absolute difference between the two numbers.
Example 1
lists=[[-3, 0, 7], [2, 5], [10, 11]] → 14

Take −3 from the first list and 11 from the third: the gap is 14.

Example 2
lists=[[-5, 20], [1, 2]] → 19

−5 and 20 come from the same list and do not count. Across lists the best is 20 and 1, a gap of 19.

Example 3
lists=[[6], [6], [6]] → 0

All numbers are equal, so the gap is 0.

Constraints
  • 2 ≤ lists.length ≤ 10⁵
  • 1 ≤ lists[i].length ≤ 500
  • -10⁴ ≤ lists[i][j] ≤ 10⁴
  • each lists[i] is sorted in non-decreasing order
  • at most 10⁵ numbers across all lists
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsTwo Boards Holding Water MediumFewest Jumps to the End MediumReach the Last Cell MediumAs Many Trades as You Like MediumWhere to Start the Lap Medium
loading Python…
Input
lists=[[-3, 0, 7], [2, 5], [10, 11]]
Expected
14

Run checks the first 3 tests in your browser. Submit checks all 98 tests on the server, hidden ones included.