it'a better to use set or map to reduce search computational complexity to logn