Arrays and Hashing Hash map lookups
60. Valid Anagram
You are given two strings s and t. Return true if t uses exactly the same letters as s, each one the
same number of times, and false otherwise. Put another way, return true when the letters of s can be
rearranged to spell t.
The order of the letters does not matter, but how many times each letter appears does. So "aab" and "aba"
match, while "aab" and "abb" do not.
Example 1
Input: s = "carthorse", t = "orchestra"
trueExplanation: Both words have nine letters: one each of a, c, e, h, o, s and t, and two of r. Only the order is different.
Example 2
Input: s = "letter", t = "settle"
falseExplanation: The two words have the same length and share most of their letters. But letter has an r where settle
has an s.
Example 3
Input: s = "aabb", t = "ab"
falseExplanation: t holds every letter that s holds, but only once each, while s has two of each. Strings of different
lengths can never match.
Check your understanding
Work out the answer for this input before you write any code.
Constraints
1 ≤ s.length, t.length ≤ 105sandthold lowercase English letters only.
Clarifying questions
What you would ask an interviewer before writing any code.