Friday, April 24, 2015

HackerRank::Algorithms::Strings::Make it Anagram

  There is no difference whether we try to change the first to look like the second one, of to change the second one to look like the first one. The thing is that if one of them has for example X 'a' letters and the other one has Y 'a' letters, then no matter what we do we need to do abs(X-Y) deletions in order to match the number of 'a' s. We have to do the same for all the 26 letters, in other words the answer is the sum of differences of each letters quantities in the strings.



No comments:

Post a Comment