Click4Ai

15.

Easy

Write a function array_intersection(arr1, arr2) that returns a sorted list of elements common to both arrays (no duplicates in output).

Example:

Input: arr1 = [1, 2, 3, 4, 5], arr2 = [3, 4, 5, 6, 7]

Output: [3, 4, 5]

Constraints:

  • Array lengths: 0 <= len(arr) <= 1000
  • Return sorted list of unique common elements
  • Test Cases

    Test Case 1
    Input: [1, 2, 3, 4, 5], [3, 4, 5, 6, 7]
    Expected: [3, 4, 5]
    Test Case 2
    Input: [1, 2, 3], [4, 5, 6]
    Expected: []
    Test Case 3
    Input: [1, 1, 2, 2], [2, 2, 3, 3]
    Expected: [2]
    + 2 hidden test cases