• + 0 comments

    Here is a O(n+m) time and O(1) space solution in python.

    O(n+m) is the average of the worse case scenarion, where all 26 chars will be present in every string. This means in the worse case the time will be O(Ch*n).

    def gemstones(arr):
        res = set(arr[0])
        
        for i in range(1, len(arr)):
            res &= set(arr[i])
        
        return len(res)