138. Intersection of two sorted arrays

JavaScriptAlgorithm
Is this helpful ?

easy  - accepted / - tried

Given 2 sorted array of integers, find the elements that exist in both arrays.

intersect(
  [1,2,2,3,4,4],
  [2,2,4,5,5,6,2000]
)
// [2,2,4]
  1. The arrays might have duplicate numbers.
  2. The order of returning result doesn't matter.
  3. What is the time & space cost of your approach? Could you improve it?

Let's try to solve this problem within 10 minutes.

Discuss(69)