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
—
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 problemGiven two strings s and t, return true if t is an anagram of s (a rearrangement using all the original letters exactly once).
▸1// t anagram of s?2return sorted(s) == sorted(t)
line 1t is an anagram of s if they use the exact same letters with the same counts. s = "anagram", t = "nagaram".