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
4mo

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!
Select
Add answer anonymously...

American Express Software Developer interview questions & answers

A Software Developer was asked 7mo agoQ. Write a program to print prime numbers from 1 to n.
A Software Developer was asked 9mo agoQ. Write a function to determine if an array of numbers are prime using streams.
A Software Developer was asked 11mo agoQ. How have you leveraged Spring Java in your projects?

Popular interview questions of Software Developer

A Software Developer was asked 7mo agoQ1. Write a program to print prime numbers from 1 to n.
A Software Developer was asked 9mo agoQ2. Write a function to determine if an array of numbers are prime using streams.
A Software Developer was asked Q3. How do you implement security in microservices?
American Express Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits