Two lowercase words are anagrams if one can be rearranged into the other, i.e. they contain exactly the same letters with the same multiplicities.
Given two words, decide whether they are anagrams of each other.
Line 1: the first word a.
Line 2: the second word b.
Print YES if a and b are anagrams, otherwise NO.
Example 1
Input
listen silent
Expected
YES
Explanation
Both words contain one each of l, i, s, e, n, t, so they are anagrams: YES.
Example 2
Input
rat car
Expected
NO
Explanation
'rat' has {r,a,t} but 'car' has {c,a,r}; the multisets differ, so NO.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →