title: Time Complexity Analysis for Word Break
body: <p>What is the time complexity analysis and the space complexity analysis for the following code:</p>
  
  <pre><code>class Solution:
      def wordBreak(self, s: str, wordDict: List[str]) -&gt; bool:
          if not s or not dict:
              False
  
          N=len(s)
          ans=[False for i in range (N+1)]
          ans[0]=True
  
  
          for index in range(N):
              if ans[index]:
                  for word in wordDict:
                      L=len(word)
                      if index+L &lt;= N and s[index:index+L]==word:
                          ans[index+L]=True
  
          return ans[-1]
  </code></pre>
  
  <p>Given a non-empty string <code>s</code> and a dictionary <code>wordDict</code> containing a list of non-empty words, determine if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p>