Copied to Clipboard
Anagram of String
Basic Accuracy: 49.25% Submissions: 22740 Points: 1

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.

Example 1:

S1 = bcadeh
S2 = hea
Output: 3
Explanation: We need to remove b, c
and d from S1.

Example 2:

S1 = cddgk
S2 = gcd
Output: 2
Explanation: We need to remove d and
k from S1.

Your Task:
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 are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.

to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.

Anagram of String

Output Window