Skip to main content
Back to problems
Leetcode
Medium
Arrays
Hash Maps
Math
Amazon
Find Missing Elements

Find the elements that are missing from an array relative to a reference range or expected set.

Acceptance 0%
Problem Statement

You are given an array of integers and some expected value range or reference sequence. Return the elements from the expected set that do not appear in the array.

The task is usually solved by tracking which values have been seen, then reporting the values that were never encountered. Depending on the exact input format, the expected set may be a contiguous range such as 1..n or another clearly defined list of values.

Input Format

  • An integer array nums.
  • Additional information describing the expected values, such as a range length n or a reference list.

Interpret the exact expected set from the problem input description.

Output Format

Return the missing value(s) in increasing order or in the required order specified by the statement.

Constraints

  • The array may contain duplicates.
  • Values are typically within a bounded integer range.
  • Aim for an approach that is linear or near-linear in time.
Examples
Sample cases returned by the problem API.

Example 1

Input

nums = [1, 2, 4, 6], expected range = 1..6

Output

[3, 5]

Explanation

The numbers 3 and 5 never appear in the array, so they are returned as the missing elements.

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.