FastPrepIntersection of Two Arrays

Intersection of Two Arrays

Bloomberg LP logoBloomberg LP● EasyNEW GRADONSITE INTERVIEW
Learn

Problem statement

Return the distinct integers that appear in both first and second, sorted in ascending order.

Function

intersection(first: int[], second: int[]) → int[]

Examples

Example 1

first = [1,2,3,4]second = [2,4,6]return = [2,4]

Only 2 and 4 occur in both arrays.

Constraints

  • Each array contains at most 10^5 signed 32-bit integers.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public int[] intersection(int[] first, int[] second) {
  // Write your code here.
}
first[1,2,3,4]
second[2,4,6]
expected[2,4]
Checking account…