Set Intersection Size At Least Two

You are given a 2D integer array intervals where intervals[i] = [starti, endi] represents all the integers from starti to endi inclusively.

A containing set is an array nums where each interval from intervals has at least two integers in nums.

Return the minimum possible size of a containing set.

Example 1
1---3
    3-------7
              8-9
Inputintervals = [[1,3],[3,7],[8,9]]
Output5
Using nums = [2, 3, 4, 8, 9] works, and it can be shown that no containing array of size 4 exists.
Example 2
1---3
1-----4
  2-----5
    3---5
Inputintervals = [[1,3],[1,4],[2,5],[3,5]]
Output3
Using nums = [2, 3, 4] works, and it can be shown that no containing array of size 2 exists.

Constraints

  • 1 <= intervals.length <= 3000
  • intervals[i].length == 2
  • 0 <= starti < endi <= 10^8

Asked at 6 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate