Talentd
FleetCode

1213. Intersection of Three Sorted Arrays

Easy80.2% acceptance2 companiesPremium elsewhere, free here

Given three integer arrays arr1, arr2 and arr3 sorted in strictly increasing order, return a sorted array of only the integers that appeared in all three arrays.

Example 1:

Input: arr1 = [1,2,3,4,5], arr2 = [1,2,5,7,9], arr3 = [1,3,4,5,8]
Output: [1,5]
Explanation: Only 1 and 5 appeared in the three arrays.

Example 2:

Input: arr1 = [197,418,523,876,1356], arr2 = [501,880,1593,1710,1870], arr3 = [521,682,1337,1395,1764]
Output: []

Constraints:

  • 1 <= arr1.length, arr2.length, arr3.length <= 1000
  • 1 <= arr1[i], arr2[i], arr3[i] <= 2000

Asked at 2 companies

Hints open one at a time

Hint 1
Count the frequency of all elements in the three arrays.
Hint 2
The elements that appeared in all the arrays would have a frequency of 3.
7:00
Still stuck?Read 2 approaches, or watch a walkthrough.
Open solution
Loading editor…
1class Solution:
2 def solve(self):
3 pass
4
Starter codePython 3Spaces: 4
Examples
Input
[1,2,3,4,5]
[1,2,5,7,9]
[1,3,4,5,8]
Input
[197,418,523,876,1356]
[501,880,1593,1710,1870]
[521,682,1337,1395,1764]
Your code is saved on this device.Solution