educative.io

Space complexity of Word Break

The space complexity of this algorithm is O(n), where n is the length of the input string. This is the space occupied by the lookup table.

On line 4, we also create a set of words in the dictionary. Should our space complexity be O(n + w)?


Course: Grokking Coding Interview Patterns in Python - Learn Interactively
Lesson: Solution: Word Break - Grokking Coding Interview Patterns in Python

1 Like

Hello @Isaac_Haseley,

The space complexity should indeed be O(n + w).
Thank you for bringing this to our attention. We will be making updates to the lesson promptly.

1 Like