click below for solution

Wednesday, 2 February 2022

Special String Solution|Codesheff starter 24 for div 3


Consider the string of infinite length obtained by repeating abcdefghijklmnopqrstuvwxyz infinitely many times. That is, it looks like abc...xyzabc...xyzabc...

Let string B be the prefix of this string of length M. For example,

  • if M=6B= abcdef
  • if M=29B= abcdefghijklmnopqrstuvwxyzabc

Vedansh calls a string X special if it contains B as a substring. Formally, X is special if for some 1LR|X|XLR=B.

Vedansh has string S of length N (consisting of lowercase Latin letters only). He wants to convert S into a special string. To do so he can perform the following operation:

  • Pick an i such that 1iN and delete Si. The remaining parts of S are concatenated.

Since Vedansh is lazy, he wants to do this in the minimum number of operations or determine if S cannot be converted to a special string. Help Vedansh in doing so.

Input Format

  • The first line of input contains a single integer T — the number of test cases. The description of T test cases follows.
  • Each test case consists of three lines of input
    • The first line of each test case contains an integer N — the length of the string S.
    • The second line of each test case contains the string S which consists of lowercase Latin letters only.
    • The third line of each test case contains an integer M — the length of the string B whose form is described in the statement.

Output Format

For each test case, if A can be converted to a special string, output the minimum number of operations to do so. Otherwise output 1.

Constraints

  • 1T1000
  • 1MN106
  • S consists of only lowercase Latin letters
  • It is guaranteed that the sum of N over all test case does not exceed 106.

Sample Input 1 

3
9
ababbdced
4
7
bdcgehx
5
6
acbcbd
3

Sample Output 1 

3
-1
1

Explanation

Test case 1M=4, so B=abcd. We can delete the following characters from Sababbdced  ababcd_, which has B as a substring.

Test case 2M=5, so B=abcde. It can be shown that S can not be converted into a special string.

Test case 3M=3, so B=abc. We can delete the following characters from Sacbcbd  abc_bd, which has B as a substring.

Solution:

solution link 1

https://shareus.in/?i=yScFNErxQ

if 1st link is not work then click on another link

Solution link 2

https://shrinke.me/0joa

Solution link 3

https://afly.pro/4dPM5oi

Solution link 4

https://afly.pro/X6gV2u4

How to get link tutorial video link

https://youtu.be/0TSsPHhgwb4