18 / 19

How do you check if two strings are anagrams of each other?

Anagram Detection

javascript
  1. 1

    Time complexity: O(n).

  2. 2

    Auxiliary space: O(k), where k is the character set size or number of distinct characters.

  3. 3

    Sorting both strings provides O(n log n) time but is usually less efficient.

  4. 4

    Case sensitivity, whitespace, Unicode normalization, and punctuation should be specified.

Difficulty: 2/10

Follow-up Questions

  • How would you handle Unicode characters?
  • Can you solve it by sorting?