This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this function expects array1 and array2 to be iterables containing capital letter characters | |
def isSubset(array1, array2): | |
hashtable = dict.fromkeys(array1, True) | |
for x in array2: | |
if not hashtable.__contains__(x): | |
return False | |
return True | |
# # By using dict to store array1, we can get hashtable key lookup performance, which is O(1). Based on this, | |
# # the complexity of the function is overall O(n), as both array1 and array2 are only traversed once, and only an O(1) |