We consider two strings to be anagrams of each other if the first string's letters can be rearranged to form the second string. In other words, both strings must contain the same exact letters in the same exact frequency. For example,
dcbac are anagrams, but
dcbad are not.
Alice is taking a cryptography class and finding anagrams to be very useful. She decides on an encryption scheme involving two large strings where encryption is dependent on the minimum number of character deletions required to make the two strings anagrams. Can you help her find this number?
Given two strings, and , that may not be of the same length, determine the minimum number of character deletions required to make and anagrams. Any characters can be deleted from either of the strings.
The only characters that match are the 's so we have to remove from and from for a total of deletions.
Complete the makingAnagrams function in the editor below.
makingAnagrams has the following parameter(s):
- string s1: a string
- string s2: a string
- int: the minimum number of deletions needed
The first line contains a single string, .
The second line contains a single string, .
- It is guaranteed that and consist of lowercase English letters, ascii[a-z].
Delete the following characters from our two strings to turn them into anagrams:
characters have to be deleted to make both strings anagrams.