Maximum number of intervals that an interval can intersect | 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
function findMaxIntervals ( v , n ) { var maxi = 0 ; for ( var i = 0 ; i < n ; i ++ ) { var c = n ; for ( var j = 0 ; j < n ; j ++ ) { if ( v [ i ] [ 1 ] < v [ j ] [ 0 ] v [ i ] [ 0 ] > v [ j ] [ 1 ] ) { c -- ; } } maxi = Math . max ( c , maxi ) ; } document . write ( maxi ) ; } var arr = [ [ 1 , 2 ] , [ 3 , 4 ] , [ 2 , 5 ] ] ; var N = arr . length ; findMaxIntervals ( arr , N ) ;