- Arrays, Dynamic Programming, Heap Sort, priority-queue, Queue, Sorting

Maximum sum of at most two non-overlapping intervals in a list of Intervals | Interval Scheduling Problem

  import java.util.*;  class GFG {          public static void main(String[] args)    {        int[][] interval            = { { 1, 3, 2 },                { 4, 5, 2 },                { 1, 5, 5 } };        int maxValue            = maxTwoNonOverLapping(interval);        System.out.println(maxValue);    }                  public static int maxTwoNonOverLapping(        int[][] interval)    {                        Arrays.sort(interval,                    (a, b) -> a[0] – b[0]);                                          PriorityQueue pq            = new PriorityQueue(                (a, b) -> a[0] – b[0]);                          int max = 0;        int ans = 0;                  for (int[] e : interval) {            while (!pq.isEmpty()) {                                                                                                  if (pq.peek()[0] >= e[0])                    break;                int[] qu = pq.remove();                                  max = Math.max(max, qu[1]);            }                          ans = Math.max(ans, max + e[2]);            pq.add(new int[] { e[1], e[2] });        }                  return ans;    }}