Word Break

Given a string A and a dictionary of words B, determine if A can be segmented into a space-separated sequence of one or more dictionary words.

Input Format:

The first argument is a string, A.
The second argument is an array of strings, B.

Output Format:

Return 0 / 1 ( 0 for false, 1 for true ) for this problem.


1 <= len(A) <= 6500
1 <= len(B) <= 10000
1 <= len(B[i]) <= 20


Input 1:
    A = "myinterviewtrainer",
    B = ["trainer", "my", "interview"]

Output 1:

Explanation 1:
    Return 1 ( corresponding to true ) because "myinterviewtrainer" can be segmented as "my interview trainer".
Input 2:
    A = "a"
    B = ["aaa"]

Output 2:

Explanation 2:
    Return 0 ( corresponding to false ) because "a" cannot be segmented as "aaa".
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Word Break on Interview Code Editor
Sign Up
to access hints and editorial solutions for Word Break
Asked In:


Click here to start solving coding interview questions