Consider a non empty string array inarr and a string instr. Identify and print outarr, based on below logic:
For the string instr, generate a list of special strings specialstringlist,
- List of special strings: A special string for a string str is generated by right shifting the characters by one position. Last character will be shifted as the first character. The newly generated special string is used as str for generating the next special string in the list. Repeat the generation until the original string str is reached.
- List of special strings would contain the string str.
Starting from the leftmost element, for each element in inarr
- Add the element of inarr to outarr if it is a subsequence in specialstringlist.
- Subsequence: A subsequence of a string strng is the possible set of characters formed from strng starting from left to right.
- If none of the elements from inarr is a subsequence of specialstringlist print -1.
Note: Perform case-insensitive comparison.
I/P
First line contains inarr with the elements separated by ‘,’ (comma)
Second line contains instr
O/P
Print outarr, with the elements separated by comma, or -1 accordingly to the standard output stream.
Sample Input 1
tarks, arkSt, kStar, trs, tSk, Stark
Sample Output 1
tarks, arkSt, kStar, trs
Sample Input 2
Czyr, ibO, craaz, Crazy
Sample Output 2
-1
