Skip to content

ORIGINAL CODING QUESTION

Fewest review visit days

Each learner is available on a closed range of integer days [start, end]. A reviewer picks some visit days, and a learner is reviewed if at least one visit day falls inside their range; one visit can serve many learners. Return the fewest visit days that review every learner.

Open practice workspace

Original exercise · medium. Editorial role relevance does not imply a company has asked this question.

Input and output

n, then n pairs (start,end).

Constraints

1 ≤ n ≤ 200; 0 ≤ start ≤ end ≤ 1000.

Example 1

Input

4 1 6 2 8 7 12 10 16

Output

2

Visits on days 6 and 12 cover everyone.

Example 2

Input

3 1 2 3 4 5 6

Output

3

The three ranges are disjoint, so three visits are needed.

Explain your approach

Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?

Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.

Hint 1

Some visit must happen by the earliest-ending range's last day.

Hint 2

Visiting as late as possible within that range serves the most other learners.

Hint 3

Sort by end; place a visit at a range's end whenever the last visit falls before its start.

Practice this question

Save your work privately, explain decisions and return to your revision queue.

Open practice workspaceBrowse the question library →