Maximum number of operations required such that no pairs from a Matrix overlap | Function to find maximum count of operations ; Initialize count by 0 ; Iterate over remaining pairs ; Check if first operation is applicable ; Check if 2 nd operation is applicable ; Otherwise ; Return the count of operations ; Driver Code
function find_max ( v , n ) { let count = 0 ; if ( n >= 2 ) count = 2 ; else count = 1 ; for ( let i = 1 ; i < n - 1 ; i ++ ) { if ( v [ i - 1 ] [ 0 ] < ( v [ i ] [ 0 ] - v [ i ] [ 1 ] ) ) count ++ ; else if ( v [ i + 1 ] [ 0 ] > ( v [ i ] [ 0 ] + v [ i ] [ 1 ] ) ) { count ++ ; v [ i ] [ 0 ] = v [ i ] [ 0 ] + v [ i ] [ 1 ] ; } else continue ; } return count ; } let n = 3 ; let v = [ [ 10 , 20 ] , [ 15 , 10 ] , [ 20 , 16 ] ] ; document . write ( find_max ( v , n ) ) ;