# CH2BERLINS - Editorial

[Practice]( Clever Berlin | CodeChef)

Author: edusanketdk
Editorialist: edusanketdk

CAKEWALK

Strings, Sets

# PROBLEM:

Given two strings you need to check whether they are formed of same set of english alphabets.

# QUICK EXPLANATION:

Compare their sets. If the two sets are equal, output `YES` else `No`.

# EXPLANATION:

We are supposed to check whether the two strings are formed of same set of characters. That means we need to check if all characters present in string A are present in string B.

A brute force approach in python would look like:

``````for i in A:
if i not in B:
print("NO")
break
else:
print("YES")
``````

But this approach is not very ideal because its redundant.
for example, letâ€™s say string A is `EEE`. So we are checking if `E` is present in string B 3 times!

So, we can simply find out distinct characters from both strings and compare them. One way to do this is to find sets of both strings and compare them.

``````if set(A) == set(B):
print("YES")
else:
print("NO")
``````

for example,

``````MNOPMNOP
ONNPM
``````

here the the two strings form the sets `{M, N, O, P}` and `{O, N, P, M}` which are ultimately equal.

But,

``````XXYYZ
XXZ
``````

here the sets are `{X, Y, Z}` and `{X, Z}`, so the strings are not made of same set of characters.

# SOLUTIONS:

Editorialist's Solution
``````for tc in range(input().strip()):
print("YNEOS"[set(input().strip()) != set(input().strip())::2]
``````