Smallest prefix to be deleted such that remaining array can be rearranged to form a sorted array | C # program for above approach ; Function to find the minimum length of prefix required to be deleted ; Stores index to be returned ; Iterate until previous element is <= current index ; Decrementing index ; Return index ; Driver code ; Given [ ] arr ; Function call
using System ; class GFG { static int findMinLength ( int [ ] arr ) { int index = ( int ) arr . Length - 1 ; while ( index > 0 && arr [ index ] >= arr [ index - 1 ] ) { index -- ; } return index ; } public static void Main ( String [ ] args ) { int [ ] arr = { 7 , 8 , 5 , 0 , - 1 , - 1 , 0 , 1 , 2 , 3 , 4 } ; int n = arr . Length ; Console . WriteLine ( findMinLength ( arr ) ) ; } }