-
Actually this problem is very simple
if we use set() function of
respective language. -
You just need to know the very basics of set theory.
-
Here we have to find those ingredients (actually the characters) which are common in all of the given dishes (actually the strings) .
-
So actually we need to find the intersection of all the inputs considering the characters in the input dish(actually a string) as the elements of the set.
-
And then we need to find the length of the set.
Python Code for the given method
#iterate through testcases
for _ in range(int(input())):
#input N <- number of dishes
N=int(input())
#input the first dish as a set and name it arr
arr=set(input())
#iterate for N-1 times for getting the other dishes
for i in range(N-1):
# take other dishes as set arr2 in each iteration
arr2=set(input())
#save in arr the value of arr (intersection) arr2
arr=arr.intersection(arr2)
# finally after all iterations output the number of elements in set arr
print(len(arr))