Traverse through count arrays and one by one pick characters . Below loop takes O ( n ) time considering the MAX is constant .
int i = 0 , j = 0 , k = 0 ; while ( k < n ) { while ( i < MAX && uCount [ i ] == 0 ) i ++ ; if ( i < MAX ) { s [ k ++ ] = ' A ' + i ; uCount [ i ] -- ; } while ( j < MAX && lCount [ j ] == 0 ) j ++ ; if ( j < MAX ) { s [ k ++ ] = ' a ' + j ; lCount [ j ] -- ; } } }