Word Break II | Backtracking (opens in new tab)
geeksforgeeks.org Problem Statement Given a string s and a dictionary wordDict, return all possible sentences where: Every word exists in the dictionary. Spaces can be inserted anywhere valid. Return all valid sentences. Brute Force Intuition Try every possible cut in the string. For every substring: Check if it exists in dictionary If yes: Take it Recursively solve remaining string If no: Skip it This naturally forms a recursion tree. Complexity Time Complexity: Exponential Space Complexity:...
Read the original article