Test

Run Settings
LanguagePython
Language Version
Run Command
# Time: O(a+b) # Space: O(a) def findCommon(arr1,arr2): assert arr1 is not None and arr2 is not None, 'arrays are none' assert len(arr1) >0 and len(arr2) >0, 'empty array' foundMap = {} for i in range(len(arr1)): if arr1[i] not in foundMap: foundMap[arr1[i]] = True for j in range(len(arr2)): if arr2[j] in foundMap: return True return False arr1= ['a','c', 'f', 'l'] arr2= ['d','c', 'i', 'j'] arr3= [] print(findCommon(arr1,arr2))
# Time: O(a+b) # Space: O(a) def findCommon(arr1,arr2): assert arr1 is not None and arr2 is not None, 'arrays are none' assert len(arr1) >0 and len(arr2) >0, 'empty array' foundMap = {} for i in range(len(arr1)): if arr1[i] not in foundMap: foundMap[arr1[i]] = True for j in range(len(arr2)): if arr2[j] in foundMap: return True return False arr1= ['a','c', 'f', 'l'] arr2= ['d','c', 'i', 'j'] arr3= [] print(findCommon(arr1,arr2))
Editor Settings
Theme
Key bindings
Full width
Lines