DP over prefix: can we split up to index i?
dp[i] = True if s[:i] can be segmented.
Transition: dp[i] = any(dp[i-l] and s[i-l:i] in dict).
Use maxLen to cap inner loop.
A valid segmentation must end with some dictionary word.
DP over prefix: can we split up to index i?
dp[i] = True if s[:i] can be segmented.
Transition: dp[i] = any(dp[i-l] and s[i-l:i] in dict).
Use maxLen to cap inner loop.
A valid segmentation must end with some dictionary word.