Choose One from Each Set to Minimize the Range
Updated
Problem statement
You are given several non-empty integer sets, represented as an array sets. Every set contains the same number of integers. Choose exactly one integer from each set.
The range of a selection is the difference between its maximum and minimum selected values.
Return the minimum possible range over all valid selections.
Function
minimumSelectionRange(sets: int[][]) → longExamples
Example 1
sets = [[30,20,10,40],[22,33,44,99],[16,17,18,19]]return = 3Choose 20, 22, and 19. The range is 22 - 19 = 3, and no selection has a smaller range.
Example 2
sets = [[1,5],[4,8]]return = 1Choosing 5 from the first set and 4 from the second produces range 1.
Example 3
sets = [[-5],[10],[3]]return = 15Every set has only one choice, so the range is 10 - (-5) = 15.
Constraints
1 ≤ sets.length ≤ 1,0001 ≤ sets[i].lengthsets[i].length = sets[0].lengthfor every validi.- The total number of integers across all sets is at most
200,000. - Every value fits in a signed
32-bit integer.
More InMobi Online Assessment questions
- Validate a Bracket SequenceOA · Seen Oct 2026
- Count Substrings Matching with One Adjacent SwapOA · Seen Oct 2026
- Maximum Subarray with Start and End WindowsOA · Seen Oct 2026
- Minimum Service Cold StartsOA · Seen Oct 2026
- Range Maximum Subarray Sum QueriesOA · Seen Oct 2026
- Connected Components with Divisor ThresholdOA · Seen Aug 2026
- Maximize Impression ValueOA · Seen Aug 2026
- Supply Path OptimizationOA · Seen Aug 2026
- Delivery ServiceOA · Seen Jun 2026
- Shared InterestOA · Seen Jun 2026
Similar questions at other companies
- Smallest Range Covering Elements from K ListsSnap Inc. · PHONE SCREENSnap Inc. interview questions
- Sliding Window MedianAuxoAI · OA
- Top K Frequent ElementsAmazon · OA · PHONE SCREEN · ONSITE INTERVIEW
- Count Servers With No Requests in a Time WindowIBM · OAIBM interview questions
- Minimum Meeting RoomsJP Morgan Chase · OAJP Morgan Chase interview questions
- Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
- Meeting Rooms IIWise · OA
- Maximum Requests in WindowSalesforce · OASalesforce interview questions
- Minimum Parking Roof LengthAmerican Express · OAAmerican Express interview questions
- Rearrange Songs by AuthorZomato / Eternal · OAZomato / Eternal interview questions