Check if the count of inversions of two given types on an Array are equal or not | C ++ Program to implement the above approach ; 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool solve ( int a [ ] , int n ) { int mx = INT_MIN ; for ( int j = 1 ; j < n ; j ++ ) { if ( mx > a [ j ] ) return false ; mx = max ( mx , a [ j - 1 ] ) ; } return true ; } int main ( ) { int a [ ] = { 1 , 0 , 2 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; bool possible = solve ( a , n ) ; if ( possible ) cout << " Yes " << endl ; else cout << " No " << endl ; return 0 ; }