Check if a string is repetition of its substring of k-length
Submissions: 1019   Accuracy:

41.15%

  Difficulty: Medium   Marks: 4

Given a string, find if it is possible to convert it to a string that is repetition of substring with k characters. To convert, we can replace one substring of length k with k characters.

Input:

The first line of input contains an integer T denoting the no of test cases. Then T test cases follow. Each test case contains an integer N, denoting the length of the string. Next line contains the string. Third line contains an integer k denoting the length of the substrings.

Output:

For each test case in a new line output will be 1/0 if true else false.
Constraints:

1<= T <= 100

2<= k < N <=50


Example:

Input

3
4
bdac
2
12
abcbedabcabc
3
5
bccak
3

Output

1
1
0

Explanation:

Test Case 1 - 

We can either replace "bd" with "ac" or "ac" with "bd".

Test Case 2 - 

Replace "bed" with "abc" so that the whole string becomes repetition of "abc".

Test Case 3 - 

k doesn't divide string length i.e. 5%3 != 0

** For More Input/Output Examples Use 'Expected Output' option **

Author: harshitsidhwa


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.