
1- Change 'a' to 'o' or vice versa
2- Change 't' to 'l' or vice versa
You are given ‘tickets’ = [‘abcd’, ‘acmfgtld’], ‘K’ = 2, and 'matchStr' = ‘aabacd’
For the ticket ‘abcd’, is equal to the substring ‘abacd’ by skipping the third character of ‘abacd’. Hence the answer is 1.
The first line of input contains a single integer ‘T’ representing the number of test cases.
The first line of input contains two space-separated integers, ‘N’ and ‘K’, representing the number of tickets and the given integer.
The second line of each test case contains a single string, representing the match string ‘matchStr’.
The next line contains ‘N’ space-separated strings representing the ticket strings.
For each test case, print a single integer representing the number of tickets that can be the winning ticket.
Print a separate line for each test case.
1 <= T <= 10
1 <= N, K <= 10^3
1 <= |tickets[i]| , |matchStr| <= 500
Time Limit: 1 sec
In this approach, we will iterate through every substring and check if any ticket in matches with the substring. If a ticket is matched, we insert it in a set to stop a ticket from being added twice.
We will create a matchChar(char1, char2) method that will check if the characters char1 and char2 are matching or not.
We will also create a function match(matchStr, ticket), which matches a matchStr with the ticket with the given conditions
Algorithm:
In this approach, we will go through each ticket and find the minimum length substring of str, which has a subsequence ticket. If the difference between the length of the current ticket and the minimum length substring is not greater than K then the ticket could be made the winning ticket.
To match the characters, we will have to take into account the conditions that the characters ‘a’ and ‘o’ are matched and the characters ‘l’ and ‘t’ are matched.
We will create a matchChar(char1, char2) method that will check if the characters char1 and char2 are matching or not.
We will also create a function minimumWindowSubstring(matchStr, subseq) which finds out the minimum substring of string that has the subsequence subseq.
Algorithm: