
If ‘STONES’ is “abAAc” and JEWELS is “Acd”.The number of jewels Ninja have is 3.
The first line of the input contains an integer, 'T,’ denoting the number of test cases.
The first line of each test case contains two integers, ‘N’ denoting the number of stones and M denoting the number of Jewels.
The second line of each test case contains an string of size N denoting ‘STONES’
The third line of each test case contains an string of size M denoting ‘JEWELS’
For each test case, print an single integer denoting the number of jewels Ninja found in the treasure box.
Print the output of each test case in a separate line.
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 10000.
1 <= M <= 52
Time Limit = 1 sec
In this approach, for each character in ‘STONES’ , we will iterate the ‘JEWELS’ string and check if the stone is a jewel or not. If we found a jewel, we will increment the ‘ANS’.
At last, we will return the ‘ANS’ corresponding to the number of jewels Ninja found.
In this approach, we will store all the characters of ‘JEWELS’ into a map, so that we can check if a stone is a jewel or not in constant time. First, we will set the value of M[ch] as 1 for all characters of the ‘JEWELS’ string. After that, we will iterate through the ‘STONES’ and if M[ch] is equal to 1, we will increment the ‘ANS’.