Coding · should-tier · asked at Amazon, Apple, Google, Meta, Microsoft, Netflix
Valid Anagram
Problem
Given two strings s and t, return True if t can be formed by rearranging the letters of s (using every letter exactly once), and False otherwise.
- Each string has at most 80,000 characters; either may be empty.
- Assume lowercase ASCII letters unless the interviewer says otherwise (see follow-ups for Unicode).
Examples
s = "brainy", t = "binary"→True. Same multiset of letters.s = "apple", t = "paper"→False.tcontainsr, whichsdoes not.s = "moose", t = "moses"→False. Same letters, butoandshave different counts.
Hints
- Two strings of different lengths can never be anagrams; check that first.
- Being an anagram is about how many of each letter, not the order.
- Count letters in one string, subtract counts while reading the other, and verify nothing is left over.
Last reviewed 8 September 2026
Locked
Approach · Solution (Python) · Complexity · Follow-ups · Company variations · Tests
The rest of this question — the worked approach, the Python solution with passing tests, complexity, follow-ups and how each company frames it — is part of the guides.
Get the full guide
Pick the company you're interviewing with. Each guide has every question tiered for that loop — one-time purchase, lifetime access.
Secure payment by Stripe · instant access · refund questions: [email protected]
Also in: Apple, Google, Meta, Microsoft, Netflix
Interviewing at more than one? All 6 guides for $499 · save $395
Not ready to buy? Get the free starter pack — 13 questions with full solutions.