Skip to content

Instantly share code, notes, and snippets.

@john012343210
Created November 9, 2018 12:07
Show Gist options
  • Save john012343210/46a0c1f6d6bcc800130580fcb2122fda to your computer and use it in GitHub Desktop.
Save john012343210/46a0c1f6d6bcc800130580fcb2122fda to your computer and use it in GitHub Desktop.
Check whether the alphabetical array is a subset of another alphabetical array. RUNNING TIME O(n)
import string
def isSubset(arr1,arr2):
d = dict.fromkeys(string.ascii_lowercase, 0)
for i in arr1:
d[i]+=1
for j in arr2:
if d[j] == 0:
return False
return True
print(isSubset(['a','b','c'],['c','b','z']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment