Problem title
Difficulty
Avg time to solve

Distribution of Money
Easy
15 mins
Letter Case Permutation
Moderate
15 mins
Product of the Last K Numbers
Easy
15 mins
Kevin And The Number On A Dice
Easy
10 mins
Digit Count In Range
Moderate
25 mins
Maximum Distinct Blocks
Easy
10 mins
Flatten 2D array
Easy
20 mins
Nearest Pallindrome
Moderate
30 mins
Find a Corresponding Node of a Binary Tree in a Clone of That Tree
Easy
20 mins
MaxFrequencyStack
Hard
45 mins

Treasure and Jewels

Difficulty: EASY
Contributed By
Avg. time to solve
30 min
Success Rate
70%

Problem Statement

Ninja luckily found a treasure hidden in his backyard. He found some stones in the treasure box and Ninja thought that these stones could be valuable. He went to a stone expert, and the expert gave him a list ‘JEWELS’ consisting of the names of all valuable jewels. Ninja made the list ‘STONES’ of all stones he found in the treasure. All stones and Jewels are represented by English characters. Now, Ninja wants to know the number of jewels he found in the treasure box. Can you help the Ninja?

Note: ‘JEWELS’ consist of distinct characters and ‘A’ and ‘a’ are treated as two different stone types.

For Example
If ‘STONES’ is “abAAc” and JEWELS is “Acd”.The number of jewels Ninja have is 3.
Input Format:
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’
Output Format:
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.
Note:
You do not need to print anything. It has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 10
1 <= N <= 10000.
1 <= M <= 52 

Time Limit = 1 sec
Sample Input 1:
2 
5 3
abAAc
Acd
4 2
acbd
Aa
Sample Output 1:
3
1
Explanation of sample input 1:
For the first test case,

Ninja has 3 jewels, one ‘c’ and two ‘A’.Hence, the answer is 3.


For the second test case:

Ninja has only 1 jewel, one ‘a’.Hence, the answer is 1.
Sample Input 2:
2
3 1
aaa
b
4 2
abcd
Bb
Sample Output 2:
0
1
Reset Code
Full screen
copy-code
Console