‹ DS&A interview · Socratic
DSA · Hashing / counting · #21

Valid Anagram

Module 24 · difficulty 1/5·30:00starts on first keystroke

Given two strings `s` and `t`, return `true` if `t` is an anagram of `s`, and `false` otherwise. An anagram uses all the original letters exactly once.

Examples
  • s = "anagram", t = "nagaram" true
  • s = "rat", t = "car" false
  • s = "a", t = "ab" false

Stuck? Reveal an animated walkthrough of the approach.

Constraints
  • · 1 <= s.length, t.length <= 5·10^4
  • · s and t consist of lowercase English letters.
Session phases
A · Clarify
B · Approach
C · Complexity
D · Edges
E · Code
F · Tradeoff
G · Score
Phase A — Clarify
Ask questions about input bounds, types, and edge constraints.
Ask the coach clarifying questions about the problem.
When you've covered this phase, advance to the next.