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