You can use any string of A multiple times.
A =[“coding”, ”ninjas”, “is”, “awesome”] target = “codingninjas”
Ans = true as we use “coding” and “ninjas” to form “codingninjas”
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.
For each test case, print 1 if you can form a target string else print 0.
The output of each test case will be printed in a separate line.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= N, | target | <= 10^2
1 <= | A[i] | <= 10
Where | A[i] | denotes length of string i,| target | denotes the length of the string target and A[i] contains only lowercase English characters.
Time limit: 1 sec
In this solution, we will try to generate all prefixes and If we want a prefix present in the string then we will recur for the remaining string.
Steps:
wordBreakHelper(s):
In this solution, we will use the Overlapping Subproblems property. We will store the already calculated result in a dp array.
Here we will store the result of our recursion in a dp array.
We can implement the above approach by –
In this solution, we will Bottom Up dp.
Here first we will store all strings of A in a hashmap. Then we will declare a dp array and run two loops and mark dp[i] true if and only if there exists a j such that substring from index j to index i is present in hashmap and dp[j] is already true.
Steps :
In this solution, we will use a graph to represent all possible solutions. The vertices are the position of first character of a word and edges will represent the whole word.
We will use a hashmap to keep track of visited nodes.
Steps :
Cakes
1-3 Palindrome
Distance to a Cycle in Undirected Graph
Randomly Sorted
8-Queen Problem