Loading...
Loading...
Loading...
Two phrases are anagrams if one uses exactly the same letters as the other, each the same number of times, like Listen and Silent. Read two phrases and print YES if they are anagrams and NO otherwise. Ignore spaces and ignore case.
YES or NO.Example 1
Input
Listen Silent
Output
YES
Example 2
Input
Dormitory Dirty room
Output
YES
The space in the second phrase is ignored.
Try the problem first. Open one hint at a time.
Use an int[26] array: one counter per letter.
Add 1 for every letter of the first phrase and subtract 1 for every letter of the second.
The phrases are anagrams exactly when every counter ends at 0.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor