Blind 75
3 / 75Free practice

Valid Anagram

Easy · Arrays & hashing

Jump to code

Given two lowercase English strings, determine whether their character counts are identical. The order of the characters does not matter.

Examples

Example 1

s = "anagram"
t = "nagaram"

Output: true

Example 2

s = "rat"
t = "car"

Output: false

Constraints

  • s and t consist of lowercase English letters.
Need a hint?

Equal lengths are necessary, but not sufficient.

Asked in real interviews

Candidates reported versions of Valid Anagram from these company interviews. Some company questions are locked and open with Premium or XP.

Browse all real coding interview questions

Accepted submissions mark this problem complete. Progress stays in this browser.

Run checks 5 examples. Submit checks all 7 cases. No account or XP needed for this problem.
Language
Case 1
Input
[
  "anagram",
  "nagaram"
]
Expected
true
Case 2
Input
[
  "rat",
  "car"
]
Expected
false
Case 3
Input
[
  "",
  ""
]
Expected
true
Case 4
Input
[
  "aacc",
  "ccac"
]
Expected
false
Case 5
Input
[
  "listen",
  "silent"
]
Expected
true

Drafts are saved per language in this browser when storage is available.