Skip to main content
Back to problems
Leetcode
Easy
Arrays
Math
Find The Integer Added To Array I

Recover the single integer that was added to one array to form another sorted array.

Acceptance 0%
Problem Statement

You are given two integer arrays, nums1 and nums2, where nums2 was formed by inserting one extra integer into nums1 and then reordering the elements.

Your task is to determine the integer that was added.

Because only one value was inserted, the original array can be matched against the larger array after accounting for the extra element.

Input Format

  • nums1: an integer array
  • nums2: an integer array with exactly one extra element compared to nums1

Both arrays contain integers and may include duplicates.

Output Format

Return the integer value that appears in nums2 but not in nums1 after the insertion.

Constraints

  • |nums2| = |nums1| + 1
  • Arrays may contain duplicate values
  • Integers may be negative, zero, or positive
Examples
Sample cases returned by the problem API.

Example 1

Input

nums1 = [2, 6, 4], nums2 = [2, 4, 6, 8]

Output

8

Explanation

After ordering the arrays, nums1 matches nums2 except for the extra value 8.

Example 2

Input

nums1 = [5, 3, 7], nums2 = [7, 5, 3, 3]

Output

3

Explanation

The value 3 is the only integer that appears one extra time in nums2.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.