Find Missing Elements
Real-world version: Absent Marker PostsThe 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.
def absent_posts(found: list[int]) -> list[int]:public List<Integer> absentPosts(int[] found)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 11 test cases: 11 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's