Problem 17
Valid Anagram
Easy · 10 pts · String, Hash Table, Sorting
Problem
You are given two strings of lowercase English letters. Decide whether the second string is an anagram of the first: whether it uses exactly the same letters, each the same number of times, possibly in a different order. Strings of different lengths can never be anagrams. A fast approach is to count how often each of the 26 letters appears in both strings and compare the counts.
Input
Two lines, each containing one lowercase string.
Output
Print true if the strings are anagrams; otherwise print false.
Constraints
1 <= length of each string <= 100000; lowercase English letters only
Example input
listen silent
Example output
true
Explanation
"listen" and "silent" each contain one e, i, l, n, s and t. The letter counts are identical, so the answer is true.