Check Whether Two Strings Are Anagrams
Company: Databricks
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Overview: Check whether two strings contain the same lowercase English letters with identical multiplicities, including empty and million-character inputs. Discuss case-sensitive contract boundaries, time and auxiliary-space expectations, Unicode generalization, inputs larger than memory, and grouping many words by anagram class.
Read the full Databricks Software Engineer interview experience this question came from
Constraints
- 0 <= len(a), len(b) <= 1,000,000.
- Both strings contain only lowercase English letters a through z.
- The empty string is an anagram of the empty string.
Examples
Input: ('', '')
Expected Output: True
Explanation: Two empty strings have identical letter multiplicities.
Input: ('', 'a')
Expected Output: False
Explanation: Different lengths cannot have the same multiplicities.
Hints
- Track the difference between the two strings' frequencies in one fixed-size array.