Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
find with sum solution in Clear category for Missing Number by kdim
def missing_number(items: list[int]) -> int:
s = min(items) + max(items) # in progression, for each item
for item in items: # must be another item with sum == s
if s - item not in items: # find them
return s - item
return s // 2
print("Example:")
print(missing_number([1, 4, 2, 5]))
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!")
Sept. 24, 2022
Comments: