Final answer:
The gemstones function takes an array of strings and returns the number of gemstones present in the array. A gemstone is represented by a string that contains only distinct characters. The function iterates over each character in the first string and checks if it is present in all the other strings.
Step-by-step explanation:
The gemstones function takes an array of strings as input and returns the number of gemstones present in the array. A gemstone is a mineral that can be cut and polished to be used in jewelry. In this case, we assume that a gemstone is represented by a string that contains only distinct characters.
To solve this problem, we can iterate over each character in the first string and check if it is present in all the other strings. If it is, we increment a count variable. Finally, we return the count variable as the number of gemstones in the array.
def gemstones(arr):
count = 0
for char in arr[0]:
is_gemstone = True
for string in arr[1:]:
if char not in string:
is_gemstone = False
break
if is_gemstone:
count += 1
return count