Skip to content

Instantly share code, notes, and snippets.

View john012343210's full-sized avatar
💭
LearnAsManyAsIcan

Nameeeee john012343210

💭
LearnAsManyAsIcan
View GitHub Profile
@john012343210
john012343210 / answer2.md
Created November 9, 2018 12:10
RUNNING TIME ANALYSIS

let the len of first array be n

it run in O(n)

create 26 letter array cost is constant, count the occuance of each letter in array1 is O(n) check whether the element in array2 is indeed in array1 is O(n)

Totally O(n)

@john012343210
john012343210 / answer1.py
Created November 9, 2018 12:07
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