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

6 Essential Sorting & Searching Coding Interview Problems

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