Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

190. Non-overlapping Intervals

MediumDay 56 of 60Greedy & Intervals

Given a list of intervals, return the minimum number of intervals you must remove so that the remaining intervals do not overlap. Intervals that only touch, like [1,2] and [2,3], do not overlap here.

Example 1
Input: intervals = [[1,2],[2,3],[3,4],[1,3]]
Output: 1
Removing [1,3] leaves [1,2],[2,3],[3,4].
Example 2
Input: intervals = [[1,2],[1,2],[1,2]]
Output: 2
Constraints
  • 1 <= intervals.length <= 10^5
  • intervals[i].length == 2
  • -5 * 10^4 <= start < end <= 5 * 10^4
Hints
Frequently asked at: Amazon, Meta, Google
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min