text: Count minimum number of moves to front or end to sort an array | C # program for the above approach ; Function that counts the minimum moves required to covert arr [ ] to brr [ ] ; Base Case ; If arr [ i ] < arr [ j ] ; Include the current element ; Otherwise , excluding the current element ; Function that counts the minimum moves required to sort the array ; If both the arrays are equal ; No moves required ; Otherwise ; Print minimum operations required ; Driver code
code: using System ; class GFG { static int minOperations ( int [ ] arr1 , int [ ] arr2 , int i , int j ) { if ( arr1 . Equals ( arr2 ) ) return 0 ; if ( i >= arr1 . Length j >= arr2 . Length ) return 0 ; if ( arr1 [ i ] < arr2 [ j ] ) return 1 + minOperations ( arr1 , arr2 , i + 1 , j + 1 ) ; return Math . Max ( minOperations ( arr1 , arr2 , i , j + 1 ) , minOperations ( arr1 , arr2 , i + 1 , j ) ) ; } static void minOperationsUtil ( int [ ] arr ) { int [ ] brr = new int [ arr . Length ] ; for ( int i = 0 ; i < arr . Length ; i ++ ) brr [ i ] = arr [ i ] ; Array . Sort ( brr ) ; if ( arr . Equals ( brr ) ) Console . Write ( "0" ) ; else Console . WriteLine ( minOperations ( arr , brr , 0 , 0 ) ) ; } static void Main ( ) { int [ ] arr = { 4 , 7 , 2 , 3 , 9 } ; minOperationsUtil ( arr ) ; } }