What is the time complexity of the following code snippet?
@Yomesh Gupta
function findIntersection(first, second) {
const firstSet = new Set(first);
return second.reduce((acc, current) => {
return firstSet.has(current) ? [...acc, current] : acc;
}, []);
}
function init() {
const first = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const second = [1, 2, 3, 4, 5];
console.log(findIntersection(first, second));
}
Option 1
O(n)
Option 2
O(n^2)
Option 3
O(nlogn)
Option 4
O(2^n)