Loading content...
You are given a sequence containing n unique integers, where each integer belongs to the closed interval [0, n]. Since the interval contains exactly n + 1 possible values but the sequence holds only n elements, precisely one value from this range is absent.
Your task is to identify and return the single integer from the range [0, n] that does not appear in the given sequence.
The sequence elements are guaranteed to be distinct, and there will always be exactly one absent value within the specified range.
nums = [3,0,1]2The sequence has 3 elements, so n = 3 and the complete range is [0, 1, 2, 3]. Comparing this range with the sequence elements {0, 1, 3}, we find that 2 is the only value not present in the sequence.
nums = [0,1]2With 2 elements in the sequence, n = 2 and the full range spans [0, 1, 2]. The sequence contains {0, 1}, leaving 2 as the absent element.
nums = [9,6,4,2,3,5,7,0,1]8This sequence contains 9 elements, making n = 9 with a range of [0, 1, 2, ..., 9]. All values from 0 to 9 are present except for 8, which is the absent element.
Constraints