Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Set Intersection Size At Least Two

XPChallenge Points: 30
levelLevel: Hard

You are given a list of intervals, where each interval [l, r] includes every integer between l and r.
Your task is to build a set of numbers such that every interval contains at least two numbers from this set.

In other words, for each interval, there must be two distinct integers from your chosen set that fall inside the interval range.

Your goal is to determine the minimum number of integers needed in such a set.

Example 1:

Input: intervals = [[2,5],[4,9],[7,10]]

Output: 4

Explanation:

One valid smallest set is [4,5,9,10], which contributes at least two numbers to every interval.

Example 2:

Input: intervals = [[1,2],[2,6],[5,7]]

Output: 3

Explanation:

A valid minimum set is [2,5,6].

Example 3:

Input: intervals = [[3,4],[6,9],[8,10]]

Output: 4

Explanation:

A possible set is [3,4,8,9], covering all three intervals with two points each.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result