Function to return true if the elements can be arranged in the desired order
static String canReorder ( int A [ ] , int n ) { HashMap < Integer , Integer > m = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( m . containsKey ( A [ i ] ) ) m . put ( A [ i ] , m . get ( A [ i ] ) + 1 ) ; else m . put ( A [ i ] , 1 ) ; } Arrays . sort ( A ) ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( m . get ( A [ i ] ) == 0 ) continue ;