Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Smallest Range Across Arrays

HardPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Smallest Range Across Arrays. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Minted can compare ordered sets of design scores from different collections. Given three non-empty arrays of integers, each sorted in nondecreasing order, find the smallest inclusive range that contains at least one number from every array.

Return the range as [low, high]. The range width is high - low. If multiple ranges have the same width, return the one with the smaller low value.

Formal Specification

Implement smallest_range(arrays), where arrays is a list containing exactly three sorted integer arrays. Return a two-element list [low, high]. A valid range must satisfy that each input array contains at least one value x such that low <= x <= high.

Constraints

  • arrays contains exactly three non-empty arrays
  • Each array is sorted in nondecreasing order
  • The total number of values across all arrays is at most 10^5
  • -10^9 <= arrays[i][j] <= 10^9
  • Values may be duplicated

Function Signature

def smallest_range(arrays):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output