Maximum number of intervals that an interval can intersect | C # program for the above approach ; Function to count the maximum number of intervals that an interval can intersect ; Store the required answer ; Traverse all the intervals ; Store the number of intersecting intervals ; Iterate in the range [ 0 , n - 1 ] ; Check if jth interval lies outside the ith interval ; Update the overall maximum ; Print the answer ; Driver code ; Function Call
using System ; using System . Collections . Generic ; class GFG { static void findMaxIntervals ( List < Tuple < int , int > > v , int n ) { int maxi = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int c = n ; for ( int j = 0 ; j < n ; j ++ ) { if ( v [ i ] . Item2 < v [ j ] . Item1 v [ i ] . Item1 > v [ j ] . Item2 ) { c -- ; } } maxi = Math . Max ( c , maxi ) ; } Console . Write ( maxi ) ; } static void Main ( ) { List < Tuple < int , int > > arr = new List < Tuple < int , int > > ( ) ; arr . Add ( new Tuple < int , int > ( 1 , 2 ) ) ; arr . Add ( new Tuple < int , int > ( 3 , 4 ) ) ; arr . Add ( new Tuple < int , int > ( 2 , 5 ) ) ; int N = arr . Count ; findMaxIntervals ( arr , N ) ; } }