Your free access ends in 7 days — and you haven’t tried it yet. Watch one algorithm run, start to finish. It takes about two minutes.

Try one problem
0
Problem

Valid Anagram

LeetCode #242Easy
Same letters, same counts?

Given two strings s and t, return true if t is an anagram of s (a rearrangement using all the original letters exactly once).

Asked atAmazonBloombergUber
step 1 / 21
a
n
a
g
r
a
m
[0][1][2][3][4][5][6]
t = "nagaram"
n
a
g
a
r
a
m
[0][1][2][3][4][5][6]
Brute force · sort
1// t anagram of s?
2return sorted(s) == sorted(t)
state

line 1t is an anagram of s if they use the exact same letters with the same counts. s = "anagram", t = "nagaram".