Tim Cooke wrote:For the purposes of copyright and correct attribution can you provide a link through to the site that this question has come from please?
Tim Cooke wrote:
Let's call the two strings s1 and s2, if s1 has 2 'a' characters and s2 has 5 'a' characters then I have to remove 3 characters from s2.
Wikipedia wrote:An anagram is direct word switch or word play, the result of rearranging the letters of a word or phrase to produce a new word or phrase, using all the original letters exactly once
Hackerrank is supposed to be good, but I have never used it
Greg Sully wrote:. . . https://www.hackerrank.com/challenges/ctci-making-anagrams
That's a pleasure
. . . Thanks Piet Souris and Campbell . . .
Although anagrams are usually written as case‑insensitive, it doesn't make any difference to the point I was trying to make.
.. the question guaranteed that two string consist of lowercase . . . .
Piet Souris wrote:Since the two strings in your opening post differ in length, there must be some removal of characters for the remaining strings to be anagrams. So, 0 is certainly incorrect.
Suppose you have two frequencymaps of the chars in both strings, and say you have a Set that contains all the chars in both strings.
For instance: string 1 has the map [ (a, 3), (b, 4) ], string 2 has the map [ (b, 2), (c, 1) ], and Set S = [a, b, c].
What to do when a char from S is present in both frequency maps, or only in one of the two?