Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Sorted + Enumerate solution in Clear category for Missing Number by Nocturne13
def missing_number(items: list[int]) -> int:
# your code here
arr = sorted(items)
d = (arr[-1] - arr[0])/len(arr)
for idx, item in enumerate(arr):
if item + int(d) != arr[idx + 1]:
return item + int(d)
print("Example:")
print(missing_number([1, 4, 2, 5]))
# These "asserts" are used for self-checking
assert missing_number([1, 4, 2, 5]) == 3
assert missing_number([2, 6, 8]) == 4
print("The mission is done! Click 'Check Solution' to earn rewards!")
Feb. 3, 2023
Comments: