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
using System ; class GFG { static bool solve ( int [ ] a , int n ) { int mx = Int32 . MinValue ; 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 ( ) { int [ ] a = { 1 , 0 , 2 } ; int n = a . Length ; bool possible = solve ( a , n ) ; if ( possible ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }