Array Difference

EasyArrays10 min4 tests

Implement a difference function that returns elements from the first array that are not present in the second array.

Example

difference([1, 2, 3, 4, 5], [2, 4]); // [1, 3, 5]
Hints (2)
  1. Convert the second array to a Set for efficient lookups.
  2. Filter the first array, keeping only elements not in the Set.

Topics

  • Arrays

Asked at

Amazon · Microsoft

Join Us
blur