We maintain two more counter arrays ctrx [ ] and ctry [ ] Ctrx [ ] maintains the count of extra elements present in string X than string Y Ctry [ ] maintains the count of characters missing from string X which should be present in string Y .
for i in range ( MAX ) : NEW_LINE INDENT if countx [ i ] > county [ i ] : NEW_LINE INDENT ctrx [ i ] += ( countx [ i ] - county [ i ] ) NEW_LINE DEDENT elif countx [ i ] < county [ i ] : NEW_LINE INDENT ctry [ i ] += ( county [ i ] - countx [ i ] ) NEW_LINE DEDENT change += abs ( county [ i ] - countx [ i ] ) NEW_LINE DEDENT for i in range ( l ) : NEW_LINE