You are not logged in. Please login at www.codechef.com to post your questions!

×

# Editorial for Chef and Secret Ingredients [ CHEFING ]

1. Actually this problem is very simple if we use set() function of respective language.

2. You just need to know the very basics of set theory.

3. Here we have to find those ingredients (actually the characters) which are common in all of the given dishes (actually the strings) .

4. 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.

5. 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))


asked 13 Feb, 17:25

112
accept rate: 0%

 0 actually I used a smaller code check my submission - Python Solution answered 13 Feb, 17:59 11●2 accept rate: 0%
 0 Instead we can use a character map and keep updating the character map for each new string and it's alphabet encountered. -- C++ Solution answered 15 Feb, 13:23 1●1 accept rate: 0%
 toggle preview community wiki:
Preview

### Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×15,852
×427
×189
×13
×8

question asked: 13 Feb, 17:25

question was seen: 322 times

last updated: 15 Feb, 13:23