Practice

Valid Anagram

Module 5 · Strings

Problem

Given two strings s and t, return whether t is an anagram of s — a rearrangement using exactly the same characters with the same multiplicities.

Examples

Example 1

Inputs = "anagram", t = "nagaram"Outputtrue

Example 2

Inputs = "rat", t = "car"Outputfalse

Constraints

1 ≤ n ≤ 5·10⁴ · lowercase English letters · follow-up: what if inputs contain arbitrary Unicode?

Attempt it first

The toolkit lesson called count arrays "frequency fingerprints" and said this problem is that observation and nothing more. Prove it to yourself before opening hints — including the early exit that makes many calls O(1).