Loading...
Loading...
A college fest app does not allow a new username that is just the letters of an existing username in a different order, such as riya and aryi.
Given two usernames, print YES if the second one uses exactly the same letters as the first, each the same number of times. Otherwise print NO.
YES or NO.Example 1
Input
riya aryi
Output
YES
Both have one r, one i, one y and one a.
Example 2
Input
aab abb
Output
NO
The first has two a, the second has two b.
Try the problem first. Open one hint at a time.
If the lengths differ, the answer is NO straight away.
Two usernames match when every letter appears the same number of times in both.
Use an int[26]: add 1 for each letter of the first username and subtract 1 for each letter of the second.
The answer is YES only if all 26 counts end at 0.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor