Take all character in mapT which occur even number of times in respective strings & simultaneously update number of characters left in map
for ( char i = ' a ' ; i <= ' z ' ; i ++ ) { if ( mapS [ i ] % 2 == 0 ) { mapT [ i ] += mapS [ i ] ; mapS [ i ] = 0 ; } else { mapT [ i ] += mapS [ i ] - 1 ; mapS [ i ] = 1 ; } if ( mapP [ i ] % 2 == 0 ) { mapT [ i ] += mapP [ i ] ; mapP [ i ] = 0 ; } else { mapT [ i ] += mapP [ i ] - 1 ; mapP [ i ] = 1 ; } }