Check if the count of inversions of two given types on an Array are equal or not | Function to check if the count of inversion of two types are same or not ; If maximum value is found to be greater than a [ j ] , then that pair of indices ( i , j ) will add extra value to inversion of Type 1 ; Update max ; Driver Code
function solve ( a , n ) { let mx = 0 ; for ( let j = 1 ; j < n ; j ++ ) { if ( mx > a [ j ] ) return false ; mx = Math . max ( mx , a [ j - 1 ] ) ; } return true ; } let a = [ 1 , 0 , 2 ] ; let n = a . length ; let possible = solve ( a , n ) ; if ( possible ) document . write ( " " ) ; else document . write ( " " ) ;