hashing · Problem 2 of 5
Valid Anagram
easy
Amazon
Google
Meta
Microsoft
Uber
Given two strings s and t, return true if t is an anagram of s, and false otherwise.
An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.
isAnagram("anagram", "nagaram") -> true
isAnagram("rat", "car") -> false
isAnagram("a", "ab") -> falseYour solution
Runs your code and animates it without grading anything. Change the input to see what it does on a case the tests do not cover.
Running is free — Submit is what records it. Or press ⌘↩
Tests
5 cases, 1 hidden| call | type | expected | result |
|---|---|---|---|
| isAnagram("anagram", "nagaram") | valid anagram | true | — |
| isAnagram("rat", "car") | different characters | false | — |
| isAnagram("a", "ab") | different lengths | false | — |
| isAnagram("listen", "silent") | identical strings | true | — |
| withheld | hidden | withheld | — |
Hidden cases run too — their inputs aren't listed here, so aim for a general solution rather than one fitted to the cases above.
Complexity
- target time
- O(n)
- target space
- O(1) auxiliary space (bounded by character set size: 26 lowercase English letters)
Single pass counting through both strings with constant space table lookup.
Hints
Stuck? Hints open one at a time, each giving a little more away.
3 hints left