Find the integers that appear in all three sorted arrays

Quick Overview

Given three integer arrays sorted in strictly increasing order, return the sorted list of values that appear in all three. The problem tests the three-pointer technique on sorted input and the argument for why advancing the smallest current value never skips a common element.

Find the integers that appear in all three sorted arrays

Company: Tripadvisor

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

Given three integer arrays `arr1`, `arr2`, and `arr3`, each sorted in strictly increasing order, return a sorted array of only the integers that appear in all three arrays. ### Function Signature ```python def arrays_intersection(arr1: list[int], arr2: list[int], arr3: list[int]) -> list[int]: ``` ### Rules - Return the common values in ascending order. - Each array is strictly increasing, so no array repeats a value and each common value appears exactly once in the output. - If no value appears in all three arrays, return an empty list. ### Constraints - `1 <= len(arr1), len(arr2), len(arr3) <= 1000` - `1 <= arr1[i], arr2[i], arr3[i] <= 2000` - Each array is sorted in strictly increasing order. ### Examples ```text Input: arr1 = [1,2,3,4,5], arr2 = [1,2,5,7,9], arr3 = [1,3,4,5,8] Output: [1,5] ``` Only 1 and 5 appear in all three arrays. The value 2 is missing from `arr3`, and 3 and 4 are missing from `arr2`. ```text Input: arr1 = [197,418,523,876,1356], arr2 = [501,880,1593,1710,1870], arr3 = [521,682,1337,1395,1764] Output: [] ``` No value appears in all three arrays (`arr1` and `arr2` already share nothing), so the result is empty.

Overview: Given three integer arrays sorted in strictly increasing order, return the sorted list of values that appear in all three. The problem tests the three-pointer technique on sorted input and the argument for why advancing the smallest current value never skips a common element.

Tripadvisor logo
Tripadvisor
Nov 24, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

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

Function Signature

def arrays_intersection(arr1: list[int], arr2: list[int], arr3: list[int]) -> list[int]:

Rules

  • Return the common values in ascending order.
  • Each array is strictly increasing, so no array repeats a value and each common value appears exactly once in the output.
  • If no value appears in all three arrays, return an empty list.

Constraints

  • 1 <= len(arr1), len(arr2), len(arr3) <= 1000
  • 1 <= arr1[i], arr2[i], arr3[i] <= 2000
  • Each array is sorted in strictly increasing order.

Examples

Input: arr1 = [1,2,3,4,5], arr2 = [1,2,5,7,9], arr3 = [1,3,4,5,8]
Output: [1,5]

Only 1 and 5 appear in all three arrays. The value 2 is missing from arr3, and 3 and 4 are missing from arr2.

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

No value appears in all three arrays (arr1 and arr2 already share nothing), so the result is empty.