Word Break Python

PROGRAM TO SOLVE WORD BREAK PROBLEM



def wordBreak(wordList, word):
    if word == '':
        return True
    else:
        wordLen = len(word)
        return any([(word[:i] in wordList) and wordBreak(wordList, word[i:]) for i in range(1, wordLen+1)])


OUTPUT:
Yes
Yes
Yes
Yes
Yes
No

Comments

Popular posts from this blog

Solve the Sudoku Python

Solve the Sudoku Java

Find Duplicates Java