I am working on some problems on Hackerrank.
John has discovered various rocks. Each rock is composed of various elements, and each element is represented by a lowercase Latin letter from 'a' to 'z'. An element can be present multiple times in a rock. An element is called a 'gem-element' if it occurs at least once in each of the rocks.
Given the list of rocks with their compositions, you have to print how many different kinds of gems-elements he has.
The first line consists of N, the number of rocks. Each of the next N lines contain rocks’ composition. Each composition consists of small alphabets of English language.
Print the number of different kinds of gem-elements he has.
1 ≤ N ≤ 100
Each composition consists of only small Latin letters ('a'-'z'). 1 ≤ Length of each composition ≤ 100
3 abcdde baccd eeabg
Explanation Only "a", "b" are the two kind of gem-elements, since these characters occur in each of the rocks’ composition.
I solved the problem but I don't feel that it is fast or pythonic. I was wondering if someone could help me increase the performance and perhaps reduce the amount of memory being used.
numRocks = int(raw_input()) rockList =  for x in xrange(numRocks): rock = raw_input() # list of sets() rockList.append(set(rock)) gemElement = 0 for x in rockList: rocks = len(rockList) - 1 count = 0 for y in rockList[1:]: if x in y: count += 1 if count == rocks: gemElement += 1 print gemElement