Ctrl K

Common to Three Sorted Arrays

Easy
You are given three arrays first, second and third, each sorted in strictly increasing order. Return an increasing array of the numbers that appear in all three arrays. Counting everything in a dictionary is easy; try to use no extra memory by taking advantage of the arrays being sorted.
Example 1
first=[2, 4, 6, 8], second=[1, 2, 3, 6, 9], third=[2, 5, 6, 7] → [2, 6]

Only 2 and 6 appear in all three arrays.

Example 2
first=[10, 20], second=[10, 30], third=[20, 30] → []

Each number appears in only two of the three arrays, so the answer is empty.

Constraints
  • 1 ≤ len(first), len(second), len(third) ≤ 1000
  • 1 ≤ elements ≤ 2000
  • Each array is strictly increasing
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsA Value Shared by Every Row MediumCleanup by Unequal Pairs MediumSpells Without Neighbors MediumPair GCDs by Sorted Position HardThe Candidate With Most Votes Easy
loading Python…
Input
first=[2, 4, 6, 8], second=[1, 2, 3, 6, 9], third=[2, 5, 6, 7]
Expected
[2, 6]

Run checks the first 3 tests in your browser. Submit checks all 82 tests on the server, hidden ones included.