# Tag: intervals

• ## Data Structures & Algorithms in Java – Intervals – Meeting rooms II

Problem: Given an array of meeting intervals , find the minimum number of conference rooms required . For example, If the meeting intervals are : [[1,10],[2,15],[15,20]] Then the number of rooms required are 2. How? First we allocate a meeting room for the first meeting [1,10]. It ends at 10. The next meeting starts at…

• ## Data Structures & Algorithms in Java – Intervals – Meeting Rooms

Problem: Given an array of meeting time intervals (start time , end time) find if all the meetings could be attended. For example, Given the input array of intervals: [[10,20],[15,30],[30,40]] Return false because the meetings [10,20] and [15,30] overlap. For the intervals [[10,30],[40,50]] Return true because the meetings don’t overlap Try out the solution here:…

• ## Data Structures & Algorithms in Java – Intervals – Non overlapping intervals

Problem: Given an array of intervals , find the minimum number of overlapping intervals that need to be removed so that the array consists of only non overlapping intervals. For example, Consider the array of intervals: [[1,2],[2,3],[3,5],[1,3]] [1,2] and [1,3] are overlapping. Also [2,3] and [1,3] are overlapping. How do you know two intervals are…

• ## Data Structures & Algorithms in Java – Intervals – Merge Intervals

Problem: Given an array of intervals , merge overlapping intervals and return the non overlapping array of intervals. For example, Given the array: [[1,3],[2,6],[8,10]] The output should be [[1,6],[8,10]] Try out the solution here: https://leetcode.com/problems/merge-intervals/ Solution: First sort the array , this makes it easier to merge overlapping intervals. Once sorted , compare two successive…

• ## Data Structures & Algorithms in Java – Intervals- Insert new interval

Problem: Given an array of sorted intervals , insert a new interval at the correct position. If the new interval overlaps with the previous interval merge them into one interval and do the same for the subsequent intervals after the new interval. For example, Given the below array of intervals: [[1,2] ,[3,5],[6,7],[8,10],[12,16]] and the new…