By Aamna Alam
Hello, in this tutorial we will take a collection of string & query arrays & determine the occurrence of query array elements in the string array.
CONCEPT BEHIND THE PROBLEM:
In this, there is a collection of input strings and a collection of query strings and for each query string, we will determine how many times it occurs in the list of input strings and then return the result array accordingly.
Example, strings=[‘ab’,’ ab’, 'abc']
queries=[‘ab’,’abc’,’bc’]
Since, there are 2 instances of ‘ab’ from queries array in strings array, 1 instance of ‘abc’, from queries array in strings array, 0 instances of ‘bc’ from queries array in strings array. Also, we take, n inputs(size of strings array) and q inputs(size of queries array)
Input: 4
aba
baba
xzxb
3
aba
xzxb
ab
Output: 2
1
0
STEPS:
1)We take inputs for string arrays and query arrays.
2)We create an array for the result.
3)We compare elements of the query array with the strings array.
4)Count the occurrence of each element of query array to string array and then store the values to the created array.
5)Print the result array.
Submitted by Aamna Alam (aamnaalam)
Download packets of source code on Coders Packet
Comments