← DiffPush

Valid anagram

Baseline Strings · Easy O(n) · O(1)

Shipment Manifest Reconciliation

Two depots transmit their part-code lists at the end of a shift, and the receiving hub must confirm the second manifest is a rearrangement of the first — identical part codes with identical multiplicities, merely shuffled. Any mismatched count, even by a single unit, flags the shipment for manual audit. Lengths that disagree make the check fail instantly.

Input: Two strings s and t.

Output: true when t is an anagram of s (same letters with the same frequencies), false otherwise.

Constraints

Examples

Example 1

Input: {"s":"anagram","t":"nagaram"}
Output: true
Both manifests use each letter exactly as often as the other — a perfect rearrangement.

Example 2

Input: {"s":"rat","t":"car"}
Output: false
Same length, but the letter inventories differ: an r appears where a c should be.

Solve this in your browser →

Also on LeetCode ↗