Stack Bash - Master data structures and algorithms

Intersection of two sorted arrays

Medium
You're given 2 sorted arrays. Write a function that returns the intersection of the arrays.
For example, given the following sorted arrays
A = [1, 4, 6, 7, 9]
B = [2, 4, 5, 6]
Your function should return numbers that exist in both arrays:
[4, 6]

Try it first

Solution

5 Essential Sorting & Searching Coding Interview Problems

Master Sorting & Searching by trying the coding challenges below.
  1. 1.Merge intervalsMedium
  2. 2.Kth largest in arrayMedium
  3. 3.Intersection of ArraysMedium
  4. 4.Search sorted matrixHard
  5. 5.Search row & col sorted matrixHard

Want to confidently pass your next coding interview?

Stack Bash helps new and veteran software engineers master data structures and algorithms for technical interviews.