Find a pair of overlapping intervals from a given Set | C # program to implement the above approach ; Function to find a pair ( i , j ) such that i - th interval lies within the j - th interval ; Store interval and index of the interval in the form of { { l , r } , index } ; Traverse the array , arr [ ] [ ] ; Stores l - value of the interval ; Stores r - value of the interval ; Push current interval and index into tup ; Sort the vector based on l - value of the intervals ; Stores r - value of current interval ; Stores index of current interval ; Traverse the vector , tup [ ] ; Stores l - value of previous interval ; Stores l - value of current interval ; If Q and R are equal ; Print the index of interval ; Stores r - value of current interval ; If T is less than or equal to curr ; Update curr ; Update currPos ; If such intervals found ; Driver code ; Given l - value of segments ; Given r - value of segments ; Given size ; Function Call
using System ; using System . Collections . Generic ; class GFG { static void findOverlapSegement ( int N , int [ ] a , int [ ] b ) { List < Tuple < Tuple < int , int > , int > > tup = new List < Tuple < Tuple < int , int > , int > > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { int x , y ; x = a [ i ] ; y = b [ i ] ; tup . Add ( new Tuple < Tuple < int , int > , int > ( new Tuple < int , int > ( x , y ) , i ) ) ; } tup . Sort ( ) ; int curr = tup [ 0 ] . Item1 . Item2 ; int currPos = tup [ 0 ] . Item2 ; for ( int i = 1 ; i < N ; i ++ ) { int Q = tup [ i - 1 ] . Item1 . Item1 ; int R = tup [ i ] . Item1 . Item1 ; if ( Q == R ) { if ( tup [ i - 1 ] . Item1 . Item2 < tup [ i ] . Item1 . Item2 ) Console . Write ( tup [ i - 1 ] . Item2 + " ▁ " + tup [ i ] . Item2 ) ; else Console . Write ( tup [ i ] . Item2 + " ▁ " + tup [ i - 1 ] . Item2 ) ; return ; } int T = tup [ i ] . Item1 . Item2 ; if ( T <= curr ) { Console . Write ( tup [ i ] . Item2 + " ▁ " + currPos ) ; return ; } else { curr = T ; currPos = tup [ i ] . Item2 ; } } Console . Write ( " - 1 ▁ - 1" ) ; } static void Main ( ) { int [ ] a = { 1 , 2 , 3 , 2 , 2 } ; int [ ] b = { 5 , 10 , 10 , 2 , 15 } ; int N = a . Length ; findOverlapSegement ( N , a , b ) ; } }