Check if the count of inversions of two given types on an Array are equal or not | Java 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
import java . io . * ; class GFG { static boolean solve ( int a [ ] , int n ) { int mx = Integer . MIN_VALUE ; for ( int j = 1 ; j < n ; j ++ ) { if ( mx > a [ j ] ) return false ; mx = Math . max ( mx , a [ j - 1 ] ) ; } return true ; } public static void main ( String [ ] args ) { int a [ ] = { 1 , 0 , 2 } ; int n = a . length ; boolean possible = solve ( a , n ) ; if ( possible ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }