Anagram comparison


  • 0

    Sid loves to read short stories. Being a Computer Science student, he decides to do some frequency analysis on his favorite reading material. For each data point, chooses a string of length a from one book, and a string of length b from a second book. The strings' lengths differ by no more than 1.

    |a-b|≤1, where |x| represents the absolute value function.

    The frequency analysis consists of checking how far the strings are from being anagrams of one another. Your challenge is to help him find the minimum number of characters of the first string he needs to change to make it an anagram of the second string. He can neither add nor delete characters from the first string. Only replacement of the characters with new ones is allowed.

    Input Format

    The first line will contain an integer T representing the number of test cases. Each test case will contain a string having length (a+b) which will be concatenation of both the strings described in problem. The string will only contain small letters and without any spaces.

    Output Format

    An integer corresponding to each test case is printed in a different line i.e., the number of changes required for each test case. Print ‘-1’ if it is not possible.

    Constraints

    1 ≤ T ≤ 100
    1 ≤ a+b ≤ 10,000

    Sample Input

    5
    aaabbb
    ab
    abc
    mnop
    xyyx

    Sample Output

    3
    1
    -1
    2
    0


  • 0

    @ashwinmanny-gmail-com I couldn't understand from the description in what company the problem was given?


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.