If there are no restrictions on spatial complexity, then this will be easy to achieve with hashmap. Assuming the numbers are not repeated in the same array.
Here is the python code for the same:
def intersection(arr_list): """ >>> intersection([[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6]]) [3, 4] >>> intersection([[1, 2, 3, 4], [2, 3, 4, 5], [5, 6]]) [] """ n = len(arr_list) ret = [] d = {} for i in arr_list[0]: d[i] = 1 for arr in arr_list[1:]: for j in arr: if j in d: d[j] += 1 for k, v in d.items(): if v == n: ret.append(k) return ret if __name__ == "__main__": import doctest doctest.testmod(verbose=True)
source share