DSA interview question
A conference has more talk proposals than one stage can host, and two talks conflict if their time ranges overlap. Talks that merely touch, where one ends exactly when the next starts, are fine. What's the minimum number of talks to cancel so the rest don't overlap? That's n minus the maximum number of compatible talks, and the maximum comes from the classic activity-selection greedy: sort by end time and keep every talk that starts at or after the last kept talk ends.
Example: [[1,2], [2,3], [3,4], [1,3]] → 1 (remove [1,3]).
int eraseOverlapIntervals(vector<vector<int>> intervals);
| Input | Output | Explanation |
|---|---|---|
[[1,2],[2,3],[3,4],[1,3]] | 1 | Remove [1,3] |
[[1,2],[1,2],[1,2]] | 2 | Keep one copy |
[[1,2],[2,3]] | 0 | Touching is allowed |
[[1,100],[11,22],[1,11],[2,12]] | 2 | Keep [1,11] and [11,22] |
[[0,2],[1,3],[2,4],[3,5],[4,6]] | 2 | Keep [0,2], [2,4], [4,6] |
(Confirm: [a,b] and [b,c] don't overlap; the answer is a count of removals.)
On Practick another engineer interviews you live for 60 minutes on a question from this bank. They have the full interviewer guide beside the call: the expected answer to every follow-up, hints to give if you stall, and a scoring rubric. You get the model solution once the session settles. It is free: interview someone for an hour and you have earned your own.
Book a free mock interviewAll 474 dsa interview questions
DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in