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.
That doesn't work because of something like "aabb". Both characters need to change, but your solution would find that there are an even number of each, so nothing needs to change. If you increment the character counts for the first half of the string and decrement for the second half, then discard the negatives and sum the positives, I think that would work.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Anagram
You are viewing a single comment's thread. Return to all comments →
That doesn't work because of something like "aabb". Both characters need to change, but your solution would find that there are an even number of each, so nothing needs to change. If you increment the character counts for the first half of the string and decrement for the second half, then discard the negatives and sum the positives, I think that would work.