Find the point where maximum intervals overlap | C # implementation of above approach ; Finding maximum starting time ; Finding maximum ending time ; reating an auxiliary array ; Lazy addition ; Lazily Calculating value at index i ; Driver code
using System ; using System . Linq ; class GFG { public static void maxOverlap ( int [ ] start , int [ ] end , int n ) { int maxa = start . Max ( ) ; int maxb = end . Max ( ) ; int maxc = Math . Max ( maxa , maxb ) ; int [ ] x = new int [ maxc + 2 ] ; int cur = 0 , idx = 0 ; for ( int i = 0 ; i < n ; i ++ ) { ++ x [ start [ i ] ] ; -- x [ end [ i ] + 1 ] ; } int maxy = int . MinValue ; for ( int i = 0 ; i <= maxc ; i ++ ) { cur += x [ i ] ; if ( maxy < cur ) { maxy = cur ; idx = i ; } } Console . WriteLine ( " Maximum ▁ value ▁ is ▁ " + maxy + " ▁ at ▁ position : ▁ " + idx + " " ) ; } public static void Main ( ) { int [ ] start = { 13 , 28 , 29 , 14 , 40 , 17 , 3 } ; int [ ] end = { 107 , 95 , 111 , 105 , 70 , 127 , 74 } ; int n = start . Length ; maxOverlap ( start , end , n ) ; } }