Function to return true if the elements can be arranged in the desired order
static String canReorder ( int [ ] A , int n ) { Dictionary < int , int > m = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( m . ContainsKey ( A [ i ] ) ) m [ A [ i ] ] = m [ A [ i ] ] + 1 ; else m . Add ( A [ i ] , 1 ) ; } Array . Sort ( A ) ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( m [ A [ i ] ] == 0 ) continue ;