Skip to content
Decoder

Valid Anagram

Easy

Problem

Two strings are anagrams when one is a rearrangement of the other: same letters, same counts, any order. Given strings s and t, return true if t is an anagram of s.

Example 1

Input
s = "listen", t = "silent"
Output
true

Example 2

Input
s = "rat", t = "car"
Output
false

Example 3

Input
s = "aab", t = "abb"
Output
false
Why
counts differ

Constraints

  • 0 <= s.length, t.length <= 5 * 10^4
  • s and t contain only lowercase English letters.

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.