Anagram difference

Jaydeep
1 min readOct 24, 2021

--

Photo by Phyllis Poon on Unsplash

Given two List of strings a and b, we need to find the minimum number of manipulations required to make each two strings anagram from the two lists.

Input : 
a = "a", "jk", "abb", "mn", "abc"
b= "bb", "kj", "bbc", "op", "def"
Output : [ -1, 0, 1, 2, 3]
Explanation: Both String contains identical characters

Input :
s1 = "a"
s2 = "bb"
Output : -1
Explanation : As the length of both the strings are not same op is -1.
Input :
s1 = "jk"
s2 = "kj"
Output : 0
Explanation : Both String contains identical characters.
Input :
s1 = "abb"
s2 = "bbc"
Output : 1
Explanation : Here, we need to change one character
in either of the strings to make them identical. We
can change 'a' and 'c' in s1 or 'c' and 'a' in s2.
Input :
s1 = "mn"
s2 = "op"
Output : 2
Input :
s1 = "abc"
s2 = "def"
Output : 3

Time Complexity: O(n), where n is the length of the string.

--

--

Jaydeep

Full Stack Programmer, love to solve problem’s during free time.