All problemsBack
Valid Anagram
easyGiven two strings s and t, return true if t is an anagram of s, and false otherwise.
An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, using all the original letters exactly once.
Test Cases
Copy an input into themain harness and Run to verifyInput
s = "anagram", t = "nagaram"Expected Output
trueInput
s = "rat", t = "car"Expected Output
falseConstraints
- 1 <= s.length, t.length <= 5 * 10^4
- s and t consist of lowercase English letters.
Hints
Hint 1 — click to reveal
Two strings are anagrams iff their character counts match.
Hint 2 — click to reveal
A 26-slot frequency array avoids hash map overhead.
Java Compiler
Powered by OneCompiler. Starter code loads automatically — edit and hit Run.