We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
If there is 1 value of "a" in the first string, and 2 values of "a" in the second string, you'd get -1. If there is a letter thats unpaired, you need to add it to the result whether its from the first or second string, hense the Math.abs.
Ex.
String: aaaab bbaaa
Array: [1, -1, 0, 0, 0, ...etc]
We need to remove 1 a and 1 b to make an anagram, so:
Math.abs(1) + Math.abs(-1) == 2, which is the correct answer.
Strings: Making Anagrams
You are viewing a single comment's thread. Return to all comments →
If there is 1 value of "a" in the first string, and 2 values of "a" in the second string, you'd get -1. If there is a letter thats unpaired, you need to add it to the result whether its from the first or second string, hense the Math.abs.
Ex.
String: aaaab bbaaa
Array: [1, -1, 0, 0, 0, ...etc]
We need to remove 1 a and 1 b to make an anagram, so: Math.abs(1) + Math.abs(-1) == 2, which is the correct answer.