Problem: Make them Anagrams

P

Given two strings, a and b , that may or may not be of the same length, determine the minimum number of character deletions required to make a and b anagrams. Any characters can be deleted from either of the strings.

Input :

  • test cases,t
  • two strings a and b, for each test case

Output:

  • Desired O/p

Constraints :

  • string lengths<=10000

Note :

Anagram of a word is formed by rearranging the letters of the word.

For e.g. -> For the word RAM – MAR,ARM,AMR,RMA etc. are few anagrams.

SAMPLE INPUTSAMPLE OUTPUT
1
cde
abc
4

#include <stdio.h>
#include <string.h>

int main(){
    int test_cases;
    scanf("%d", &test_cases);                 
    
    for(int i=0;i<test_cases;i++)
    {
        char str1[10001],str2[10001];
        int letters1[26],letters2[26];
        scanf("%s",str1);
        scanf("%s",str2);

        memset(letters1,0,26*sizeof(int));
        memset(letters2,0,26*sizeof(int));
        
        for(int j=0;j<strlen(str1);j++)
            letters1[tolower(str1[j])-'a']+=1;
        for(int j=0;j<strlen(str2);j++)
            letters2[tolower(str2[j])-'a']+=1;

        int result = 0;
        for(int j=0;j<26;j++)
            result += labs(letters1[j] - letters2[j]);
        
        printf("%d\n",result);

    }
    return 0;
}
Disclaimer: The present content may not be used for training artificial intelligence or machine learning algorithms. All other uses, including search, entertainment, and commercial use, are permitted.

Categories

Tags