Help Me In Murder Mystery!

Please Help Me I Am Not Able To Solve This Question
Link: CodeChef: Practical coding for everyone
Thanks And Regards
koolprogrammer

You can check my code code
I have simply hashed the given two to get frequency of each character present in each of the strings
And at last i have simply compared their frequencies .

@dontcheckme Thanks For Answering My Question But I Am More Fluent In Java Soo… Can You Please Explain The Structure Of The Answer

I have solved this problem in Python, problem has solved and submitted but still I guess it takes big amount of time for execution.

t = int(input())
for _ in range(t):
    key = str(input())
    words = str(input())
    key_set = {}
    word_set = {}
    for i in key:
        key_set[i] = key.count(i)
        word_set[i] = words.count(i)
    length = len(set(key_set.keys()))
    flag = 0
    for i in key_set.keys():
        if key_set[i] <= word_set[i]:
            flag += 1

        
    if flag == length:
        print("YES")
    else:
        print("NO")

It’s python code you will easily understand.

@jaimin_1618 Thanks For Answering My Question, But Java Is More Easier To Me