Allie is good friends with Samuel. It is Samuel's birthday and Allie brought a gift for him.
Question:
Allie is good friends with Samuel. It is Samuel's birthday and Allie brought a gift for him. The gift is a game called Happy strings. For playing the game, Allie picks up a
string and chooses a number A. Samuel has to find the maximum distance (distance is given by the number of characters in between) between any 2 subsequent same
characters in the string S given that a character X is said to be present at index i if it is present in any of the index from |i - A| to |i + A|.
Input Specification:
input1: S, denoting the string in the game containing only characters 'A' - 'Z'.
input2: A, the number chosen by Allie.
input3: Length of input1
Output Specification:
Your function should return the maximum distance between any 2 same characters satisfying the given constraint.
Example 1:
input1: AABAABAA
input2: 1
input3: 8
Output: 0
Explanation:
Considering character A - Maximum distance = 0.
Considering character B - Maximum distance = 0.
Example 2:
input1: AABAAABAA
input2: 1
input3: 9
Output: 1
Explanation:
Considering character A - Maximum distance = 0.
Considering character B - Maximum distance = 1.
Example 3:
input1: HFJDHSUFNFJSYFMFISHNRJKFUJSN
input2: 2
input3: 23
Output: 13