Reduce the array by deleting elements which are greater than all elements to its left | C # program for the above approach ; Function to implement merging of arr [ ] ; Function to delete all elements which satisfy the condition A [ i ] > A [ i - 1 ] ; Divide array into its subarray ; Getting back merged array with all its right element greater than left one . ; Driver Code ; Given array arr [ ]
using System ; using System . Collections . Generic ; class GFG { static List < int > merge ( List < int > x , List < int > y ) { foreach ( int i in y ) { if ( x [ x . Count - 1 ] > i ) x . Add ( i ) ; } return x ; } static List < int > mergeDel ( List < int > l ) { if ( l . Count == 1 ) return l ; int m = l . Count / 2 ; List < int > temp1 = l . GetRange ( 0 , m ) ; List < int > temp2 = l . GetRange ( m , l . Count - m ) ; return merge ( mergeDel ( temp1 ) , mergeDel ( temp2 ) ) ; } public static void Main ( string [ ] args ) { List < int > arr = new List < int > { 5 , 4 , 3 , 2 , 1 } ; List < int > ans = mergeDel ( arr ) ; Console . Write ( " [ ▁ " ) ; foreach ( int x in ans ) Console . Write ( x + " , ▁ " ) ; Console . Write ( " ] " ) ; } }