Assume n is the maximum of number of size of two arrays.
- The complexity to transform two array to two hashset -> O(n) * 2
val firstSet = firstArray.toSet()
- The complexity to loop the second set -> O(log n) * The complexity to check whether a char is exist in first set -> O(1)
- The size of the sets may smaller than original one, since it may have duplicate character.
- Each call for Set().contain(Int) cost
O(1)
time.
Combining all complexity. The complexity of function isSubset
is
- 2 * O(n) + O(log n) ->
O(n)