Word Break Problem Statement

You are given a list of N strings called A. Your task is to determine whether you can form a given target string by combining one or more strings from A.

The strings from A can be used multiple times to form the target.

Example:

Input:
A = ["coding", "ninjas", "is", "awesome"]
target = "codingninjas"
Output:
true
Explanation:

We can use the strings "coding" and "ninjas" to form the target "codingninjas".

Input:

The first line of input contains a single integer T, representing the number of test cases or queries to be run.
Then the T test cases follow.
The first line of each test contains a single integer N denoting the total number of strings in A.
The second line of each test contains "N" space-separated strings of A.
The third line of each test contains a single string target.

Output:

For each test case, print 1 if you can form a target string, otherwise print 0.
The output of each test case will be printed in a separate line.

Constraints:

  • 1 <= T <= 5
  • 1 <= N, | target | <= 102
  • 1 <= | A[i] | <= 10
  • Strings in A contain only lowercase English characters.
Note:
You do not need to print anything; it has already been handled. Just implement the given function.
AnswerBot
4d

Given a list of strings, determine if a target string can be formed by combining one or more strings from the list.

  • Iterate through all possible combinations of strings from the list to form the target...read more

Help your peers!
Add answer anonymously...
American Express Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter