The problem is as follows: Given two arrays, write a function to compute their intersection.

The below code is my solution.I'm just curious as to what the space time and complexity of below algorithm would be.

var intersection = function(nums1, nums2) {
    const intersectionArr =  nums1.filter((value)=> nums2.includes(value));
    return [...new Set(intersectionArr)];
  • 1
    \$\begingroup\$ Please add tag of the language in which this is written (I suppose js?) Despite i think question purely about complexity iss offtopic on this site, the time complexity Is probably O(n^2) And Space Is O(n). \$\endgroup\$ – slepic Dec 25 '19 at 9:03

Browse other questions tagged or ask your own question.