Anagram check

What is the fastest way to check whether two strings are anagrams, and its complexity?

Show hints (2)+
  1. Anagrams have identical multisets of characters.
  2. Counting beats sorting asymptotically.

Answer

Reveal answer →

Compare character-frequency counts — $O(n)$

Want the full step-by-step worked solution? It's part of Premium — along with a worked solution for every question in the bank.

Asked at: Optiver, IMC

Related questions