Function to check if the intervals can be added by X to form non - overlapping intervals
public static Boolean checkNonOverlapping ( ArrayList < ArrayList < Integer > > arr , int n ) { ArrayList < Integer > dsu = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < n + 1 ; i ++ ) { dsu . add ( i ) ; } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) {