Check Whether Two Words Are Case-Insensitive Anagrams
Company: Upstart
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Online Assessment
Overview: Compare letter multiplicities case-insensitively to recognize anagrams, including repeated letters and empty strings.
Constraints
- Both word_a and word_b are defined strings and may be empty.
- Each string has length at most 30.
- Characters are uppercase or lowercase English letters (A-Z, a-z) only.
- Repeated letters must occur equally often in both words.
- Two empty strings are anagrams.
- The return value is a boolean.
Examples
Input: ('', '')
Expected Output: True
Explanation: Minimum valid input: two empty strings hold the same (empty) letter multiset, so they are anagrams.
Input: ('', 'a')
Expected Output: False
Explanation: One word is empty and the other has a letter, so the multisets differ.
Hints
- Knowing that both words contain the letter 'a' does not reveal whether they contain it the same number of times: compare quantities, not just membership.
- Letter case must never change the answer, so decide early how you will make 'A' and 'a' indistinguishable before anything else compares them.
- There is a cheap property of the two words that must already agree before any letter comparison can succeed.