Skip to content

Files

Latest commit

 

History

History
29 lines (22 loc) · 2.26 KB

File metadata and controls

29 lines (22 loc) · 2.26 KB

Non-overlapping Intervals medium #javascript #blind75 #intervals #greedy

by Pawan Kumar @jsartisan

Take the Challenge

Given an array of intervals where intervals[i] = [start_i, end_i], find the minimum number of intervals to remove to make the remaining intervals non-overlapping.

Rules:

  • Intervals with common endpoints are considered non-overlapping
  • Must remove minimum number of intervals
  • Intervals overlap if they share any points except endpoints

Constraints:

  • 1 ≤ intervals.length ≤ 1000
  • intervals[i].length == 2
  • -50000 ≤ start < end ≤ 50000

Examples:

// Example 1:
console.log(eraseOverlapIntervals([[1,2],[2,4],[1,4]]));
// Output: 1
// Explanation: Remove [1,4] to make non-overlapping

// Example 2:
console.log(eraseOverlapIntervals([[1,2],[2,4]]));
// Output: 0
// Explanation: Already non-overlapping

Back Share your Solutions Check out Solutions