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 function
#include <bits/stdc++.h> NEW_LINE using namespace std ; void find_missing ( vector < pair < int , int > > interval ) { sort ( interval . begin ( ) , interval . end ( ) ) ; int mx = 0 ; for ( int i = 0 ; i < ( int ) interval . size ( ) ; ++ i ) { if ( interval [ i ] . first > mx ) { cout << mx ; return ; } else mx = max ( mx , interval [ i ] . second + 1 ) ; } cout << mx ; } int main ( ) { vector < pair < int , int > > interval = { { 0 , 14 } , { 86 , 108 } , { 22 , 30 } , { 5 , 17 } } ; find_missing ( interval ) ; return 0 ; }