Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
Space complexity is wrong -> O(1)

shanehowe100

Aug 30, 2024

As mentioned in one of the constraints

  • str and pat consist of lowercase English letters

This means when building our hashmap from pat in the worst case it will grow to O(26) . This is a constant number and can be simplified to O(1)

1

0

Comments
Felix Pherry
Felix Pherrya year ago

agreed. it can only grow to O(26). I'd also argue that the time complexity is just O(N). We don't really care bout the m since we know that M <= N anyways. It's like we simplify O(2N) to O(N) in this case.