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

0% completed

Vote For New Content
I personally like going without the matched variable and instead checking if the...

Christian Salinas

Jul 22, 2022

I personally like going without the matched variable and instead checking if the character frequency for the pattern is zero. Something like this in python:

if all(v ==0 for v in char_frequency.values()): return True

1

0

Comments
Comments
V
Viktor 3 years ago

more costly from the computational perspective, I guess?

D
Douglas 3 years ago

yes, you would be iterating through the whole HashMap to do this check in every iteration. The time complexity would get multiplied by the size of the HashMap

On this page