Time complexity is: O(n)
-
The first loop takes O(n) to insert all the elements in the Hashset
-
The second loop takes O(n) to loop through the query array, to check if the elemets are present in Hashset.
-
So O(n) + O(n) = O(n)
The worst case time complexity of my algorithm is still O(n)