Given two arrays, how to find the maximum element which is common to both the arrays?
I was thinking of sorting both the arrays(n log n) and then perform the binary sear
Not a perfect, but a simple solution, O(len(array1) + len(array2))
import sys
def find_max_in_common(array1, array2):
array1 = set(array1)
array2 = set(array2)
item_lookup = {}
for item in array1:
item_lookup[item] = True
max_item = -sys.maxsize
intersection = False
for item in array2:
if not item_lookup.get(item, None):
continue
else:
intersection = True
if item > max_item:
max_item = item
return None if not intersection else max_item