Check if removal of a subsequence of non | C # for the above approach ; Function to check if it is possible to sort the array or not ; Stores the index if there are two consecutive 1 's in the array ; Traverse the given array ; Check adjacent same elements having values 1 s ; If there are no two consecutive 1 s , then always remove all the 1 s from array & make it sorted ; If two consecutive 0 ' s ▁ are ▁ ▁ present ▁ after ▁ two ▁ consecutive ▁ ▁ 1' s then array can 't be sorted ; Otherwise , print Yes ; Driver code
using System . IO ; using System ; class GFG { static void isPossibleToSort ( int [ ] arr , int N ) { int idx = - 1 ; for ( int i = 1 ; i < N ; i ++ ) { if ( arr [ i ] == 1 && arr [ i - 1 ] == 1 ) { idx = i ; break ; } } if ( idx == - 1 ) { Console . WriteLine ( " YES " ) ; return ; } for ( int i = idx + 1 ; i < N ; i ++ ) { if ( arr [ i ] == 0 && arr [ i - 1 ] == 0 ) { Console . WriteLine ( " NO " ) ; return ; } } Console . WriteLine ( " YES " ) ; } static void Main ( ) { int [ ] arr = { 1 , 0 , 1 , 0 , 1 , 1 , 0 } ; int N = arr . Length ; isPossibleToSort ( arr , N ) ; } }