Given two strings S1 and S2 in lowercase, the task is to make them anagram. The only allowed operation is to remove a character from any string. Find the minimum number of characters to be deleted to make both the strings anagram. Two strings are called anagram of each other if one of them can be converted into another by rearranging its letters.
Input: S1 = bcadeh S2 = hea Output: 3 Explanation: We need to remove b, c and d from S1.
Input: S1 = cddgk S2 = gcd Output: 2 Explanation: We need to remove d and k from S1.
Complete the function remAnagram() which takes two strings S1, S2 as input parameter, and returns minimum characters needs to be deleted.
Expected Time Complexity: O(max(|S1|, |S2|)), where |S| = length of string S.
Expected Auxiliary Space: O(26)
1 <= |S1|, |S2| <= 105
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?Yes