Problem Β· String
Anagram Difference πΏ
Learn this problemProblem statement
An anagram is a word whose characters can be rearranged to create another word. Given two strings, determine the minimum number of characters in either string that must be modified to make the two strings anagrams. If it is not possible to make the two strings anagrams, return -1.
Function
getMinimumDifference(a: String[], b: String[]) β int[]
Complete the function getMinimumDifference in the editor.
getMinimumDifference has the following parameter(s):
- 1.
String[] a: an array of strings - 2.
String[] b: an array of strings
Returns
int[]: the minimum number of characters in either string that needs to be modified to make the two strings anagrams or -1 if it is not possible
Examples
Example 1
a = ["tea", "tea", "act"]b = ["ate", "toe", "acts"]return = [0, 1, -1]
a[0] = teaandb[0] = ateare anagrams, so 0 characters need to be modified.a[1] = teaandb[1] = toeare not anagrams. Modify 1 character in either string (o -> a or a -> o) to make them anagrams.a[2] = actandb[2] = actsare not anagrams and cannot be converted to anagrams because they contain different numbers of characters.- The return array is
[0, 1, -1]