Facebook PixelValid Anagram — Coding Practice
Valid AnagramEasy

Valid Anagram

Easy 9.8k64% acceptance
StringHash TableSorting

Given two strings s and t, return true if t is an anagram of s — i.e. it uses exactly the same characters with the same frequencies, just reordered.

Example 1
Input: s = "anagram", t = "nagaram"
Output: true
Example 2
Input: s = "rat", t = "car"
Output: false
Constraints
  • 1 ≤ s.length, t.length ≤ 5·10⁴
  • s and t consist of lowercase English letters.
Asked atAmazonBloombergUber
JavaScript
Loading editor…
Case 1
"anagram", "nagaram"
expected: true
Case 2
"rat", "car"
expected: false
Case 3
"a", "ab"
expected: false