Grokking the Coding Interview: Patterns for Coding Questions
0% completed
Solution: Valid Anagram
.....
.....
.....
Like the course? Get enrolled and start learning!
A
Anonymous
· 2 years ago
Since our two input strings s and t are only to be comprised of lowercase english letters, this sets the maximum number of unique letters we could encounter to be 26, regardless of string size. Because of this, our mapping of letters to counts is never going to contain more than 26 active keys at any moment. Thus, our space complexity is bounded to O(26) = O(1).
However, the space demand does not grow reliably as a function of the string input size, meaning it is not O(N) space.
A
Anonymous
· 3 years ago
Return the following:
return sorted(s) == sorted(t)
Show 1 reply
Reading Progress
0%