You are not logged in. Please login at 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

    #input the first dish as a set and name it arr

    #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

        #save in arr the value of arr (intersection) arr2

    # finally after all iterations output the number of elements in set arr

asked 13 Feb, 17:25

pratyaydeep's gravatar image

accept rate: 0%

edited 15 Feb, 00:28

actually I used a smaller code check my submission - Python Solution


answered 13 Feb, 17:59

pratyaydeep's gravatar image

accept rate: 0%

edited 13 Feb, 18:00

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

pranjal01shi's gravatar image

accept rate: 0%

toggle preview

Follow this question

By Email:

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



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • 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:


question asked: 13 Feb, 17:25

question was seen: 322 times

last updated: 15 Feb, 13:23