Back

Valid Anagram

easy

Given 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 the main harness and Run to verify
Input
s = "anagram", t = "nagaram"
Expected Output
true
Input
s = "rat", t = "car"
Expected Output
false

Constraints

  • 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.