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
def findMaxIntervals ( v , n ) : NEW_LINE INDENT maxi = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT c = n NEW_LINE for j in range ( n ) : NEW_LINE INDENT if ( v [ i ] [ 1 ] < v [ j ] [ 0 ] or v [ i ] [ 0 ] > v [ j ] [ 1 ] ) : NEW_LINE INDENT c -= 1 NEW_LINE DEDENT DEDENT maxi = max ( c , maxi ) NEW_LINE DEDENT print ( maxi ) NEW_LINE DEDENT arr = [ ] NEW_LINE arr . append ( ( 1 , 2 ) ) NEW_LINE arr . append ( ( 3 , 4 ) ) NEW_LINE arr . append ( ( 2 , 5 ) ) NEW_LINE N = len ( arr ) NEW_LINE findMaxIntervals ( arr , N ) NEW_LINE