Common Elements

ARRAY

Problem

Given two integer arrays, arr1 and arr2, return an array of their intersection. Each element in the result must be unique, and the result should be returned in ascending order.

Examples

commonElements([3,3,3], [3,3]) // returns [3] // The number 3 appears in both arrays, // so the result is [3]. commonElements([1,7,8,9], [5,6,7,8]) // returns [7,8] // The numbers 7 and 8 are common to both arrays, // and they are returned in ascending order. commonElements([10,11,12], [1,2,3]) // returns [] // There are no common elements between the two arrays, // so an empty array is returned.
Loading...