# Subsequence Game

Contributed by
Jaypal Mudaliyar
Last Updated: 23 Feb, 2023
Medium
0/80
Avg time to solve 20 mins
Success Rate 65 %
Share

## Problem Statement

#### But Shail is busy with his birthday celebration and cannot solve the task, but want to make his parents happy by giving them the answer to the task, So being his friend he asked you to solve this problem, Can you help him?.

##### EXAMPLE :
``````Input: ‘N’ = 5, ‘M' = 2, ‘STR’ = “abcde” , ‘ARR’ = [“ad”, “cb”]

Output: 1
In this case, string “ad” occurs as a subsequence in the string ‘STR’ and the index of the match is ‘0’ and ‘3’ respectively. Also, string “cb” isn’t a subsequence because there is no occurrence of ‘b’ after the first ‘c’ at index ‘2’. Hence the output will be ‘1’.
``````
Detailed explanation ( Input/output format, Notes, Images )
##### Constraints :
``````1 <= ‘T’ <= 10
1 <= ‘N’ <= 10^4
STR.length = N
1 <= ‘M’ <= 10^4
‘STR’ only consists of lowercase English letters.
It is guaranteed that sum of ‘N’ over all test cases is <= 10^5
It is guaranteed that sum of lengths of strings in array ‘ARR’ over all test cases is <= 10^5
Time Limit: 1 sec
``````
##### Sample Input 1 :
``````2
5 1
virat
vat
10 3
helloworld
oo
abcdefghijk
hewd
``````
##### Sample Output 1 :
``````1
2
``````
##### Explanation Of Sample Input 1 :
``````For the first test case,
The matching sequence index for string “vat” is = [‘0’, ‘3’, ‘4’].

Hence, the output will be: 1

For the second test case,
The matching sequence index for string “oo” is = [‘4’, ‘6’].
There is no matching sequence index for string “abcdefghijk”.
The matching sequence index for string “hewd” is = [‘0’, ‘1’, ‘5’, ‘9’].

Hence, the output will be: 2
``````
##### Sample Input 2 :
``````2
10 4
btovxbkumc
btovxbku
to
zueoxxxjme
yjkclbkbtl
26 2
bcdaefhgikjlmonprqstuvxwzy
empty
abcdefghijklmnopqrstuvwxyz
``````
##### Sample Output 2 :
``````2
1
``````
Auto
Console