This problem will help you to get experience on where to use the set even if it is not mentioned in the problem statement. It might be helpful to use the Set if you encounter a similar problem during your interview. This is because it demonstrates knowledge of a commonly used data structure and a background in mathematics.
xxxxxxxxxx65
'PASSED: `intersection([4,17,4,4,15,16,17,6,7],[15,2,6,20,17,17,8,4,5])` should return `[15,6,17,4]`'var assert = require('assert');function intersection(nums1, nums2) { // fill this in return [];}try { assert.deepEqual(intersection([6, 0, 12, 10, 16], [3, 15, 18, 20, 15]), []); console.log( 'PASSED: `intersection([6,0,12,10,16],[3,15,18,20,15])` should return `[]`' );} catch (err) { console.log(err);}try { assert.deepEqual(intersection([1, 5, 2, 12, 6], [13, 10, 9, 5, 8]), [5]); console.log( 'PASSED: `intersection([1,5,2,12,6],[13,10,9,5,8])` should return `[5]`' );} catch (err) { console.log(err);}OUTPUT
Results will appear here.