Given two strings, X and X, that may or may not be of the same length, determine the minimum number of character deletions required to make X and X anagrams. Any characters can be deleted from either of the strings.
Constraints
process.stdin.resume();
process.stdin.setEncoding('ascii');
var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;
process.stdin.on('data', function (data) {
input_stdin += data;
});
process.stdin.on('end', function () {
input_stdin_array = input_stdin.split("\n");
main();
});
function readLine() {
return input_stdin_array[input_currentline++];
}
function main() {
var a = readLine();
var b = readLine();
/////////////// Start Code Here ////////////////////
aOne = a.split("");
aTwo = b.split("");
// aThree = [];
counter = 0;
// If you reverse engineer, you will find that the number of times it takes to remove elements is the sum the lengths of the arrays, minus the amount of correct unique number combinations.
if (aOne.length < aTwo.length){
for (let j = 0; j < aOne.length; j ++) {
for (let i = 0; i < aTwo.length; i ++ ){
if (aOne[j] === aTwo[i]) {
counter ++;
aTwo[i] = 0; //ensures elements are not counted twice
break;
}
}
}
console.log(aTwo.length + aOne.length - (counter * 2));
} else {
for (let i = 0; i < aTwo.length; i ++) {
for (let j = 0; j < aOne.length; j++) {
if (aTwo[i] === aOne[j]) {
counter++;
aOne[j] = 0; //ensures elements are not counted twice
break;
}
}
}
console.log(aOne.length + aTwo.length - (counter * 2));
}
}