Find least non | C # program to find the least non - overlapping number from a given set intervals ; Function to find the smallest non - overlapping number ; Sort the intervals based on their starting value ; Check if any missing value exist ; Finally print the missing value ; Driver code
using System ; using System . Collections . Generic ; class GFG { class Pair : IComparable < Pair > { public int start , end ; public Pair ( int s , int e ) { start = s ; end = e ; } public int CompareTo ( Pair p ) { return this . start - p . start ; } } static void findMissing ( List < Pair > interval ) { interval . Sort ( ) ; int mx = 0 ; for ( int i = 0 ; i < interval . Count ; ++ i ) { if ( interval [ i ] . start > mx ) { Console . WriteLine ( mx ) ; return ; } else mx = Math . Max ( mx , interval [ i ] . end + 1 ) ; } Console . WriteLine ( mx ) ; } public static void Main ( String [ ] args ) { List < Pair > interval = new List < Pair > ( ) ; interval . Add ( new Pair ( 0 , 14 ) ) ; interval . Add ( new Pair ( 86 , 108 ) ) ; interval . Add ( new Pair ( 22 , 30 ) ) ; interval . Add ( new Pair ( 5 , 17 ) ) ; findMissing ( interval ) ; } }