Recursion: Beautiful String

Prince Patel
By -
0

Recursion: Beautiful String

You are given an array of N strings and an additional string K. The string K is beautiful if the following conditions hold true: 

  1. The string K is a combination of one or more of N strings. 
  2. The combination is formed by concatenating one or more of the N strings in any order. 
  3. Each string in the combination can be used multiple times as well.

You need to determine whether the string K is beautiful or not, and if it is beautiful, you need to print the sequence in which the selected strings from the set of N strings are concatenated.

Example:

Value of N = 3 and the set of strings is ["abra", "ka", "dabra"]. 
The string K = "kaabra". The string K is formed by concatenating the strings "ka" and "abra". 
Hence, the answer is "ka abra".

Function Description 

In the provided code snippet, implement the provided isBeautiful(...) method using the variables to print the sequence in which the selected strings from the set of N strings are concatenated. You can write your code in the space below the phrase “WRITE YOUR LOGIC HERE”

There will be multiple test cases running so the Input and Output should match exactly as provided. 

The base Output variable result is set to a default value of -404 which can be modified. Additionally, you can add or remove these output variables. 

Input Format

The first line of each test case contains N, denoting the number of strings.
The second line contains N space-separated strings, S[i], that represent the i'th string. 
The third line contains a string, K, denoting the string K

Sample Input


abra ka dabra 
kaabra 


Constraints 

1 ≤ N ≤ 10 
1 ≤ |S[i]| ≤ 10 
1 ≤ K ≤ 2000 

Output Format 

The output format contains a space-separated sequence in which the selected strings from the set of N strings are concatenated. 

Sample Output 

ka abra 

Explanation 

Here, the string K is formed by concatenating the strings "ka" and "abra". Hence, the answer is "ka abra".


Solution:

Post a Comment

0Comments

Post a Comment (0)