Easy · Arrays

Find intersection of two sorted arrays

Given two integer arrays a and b, each sorted in non-decreasing order, return the values common to both in ascending order, repeating a value as many times as it appears in both arrays (the smaller of its two counts).

Examples

Example 1

[1,2,4,5,6] ∩ [2,3,5,7]

Output: [2, 5]

Example 2

[1,3,5,7] ∩ [2,4,6,8]

Output: []

Rebuild it in the studio

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Arrays problems