Improved the time complexity to linear now, using intersect
Improved the time complexity to linear now, using intersect