Show problems as
Classic problem #3731EasyArrayHash TableSorting

Find Missing Elements

Real-world version: Absent Marker Posts
Tracked in this browser only
Read Find Missing Elements on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

A survey crew walks a trail and notes the number stamped on every marker post it comes across. found[i] is the number on the i-th post noted down. The crew doubles back a few times, so the notes are in no particular order and a post can appear in them more than once.

Take the smallest number in found and the largest number in found. Return, in increasing order, every whole number that lies strictly between those two and does not appear anywhere in found. Return an empty list when there is no such number.

Examples

Example 1

Input
found = [17, 12, 20, 12, 15]
Output
[13, 14, 16, 18, 19]

The notes run from 12 up to 20, and of the numbers in between only 15 and 17 were noted, so the rest are reported.

Example 2

Input
found = [63, 61, 62]
Output
[]

The span from 61 to 63 has just 62 inside it, and 62 was noted, so nothing is missing.

Example 3

Input
found = [88, 88]
Output
[]

The smallest and largest notes are the same number, so the span between them holds nothing at all.

Constraints

  • 2 <= found.length <= 100
  • 1 <= found[i] <= 100

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def absent_posts(found: list[int]) -> list[int]:
Java
public List<Integer> absentPosts(int[] found)