Skip to content

Instantly share code, notes, and snippets.

@ZechCodes
Last active January 27, 2021 00:30
Show Gist options
  • Save ZechCodes/055fb77a49fa4d6777be7f9112bbd701 to your computer and use it in GitHub Desktop.
Save ZechCodes/055fb77a49fa4d6777be7f9112bbd701 to your computer and use it in GitHub Desktop.
Challenge 171 - Sum of Missing Numbers

Challenge 171 - Sum of Missing Numbers

Create a function that returns the sum of missing numbers from the given list.

Examples

sum_missing_numbers([4, 3, 8, 1, 2]) ➞ 18
# 5 + 6 + 7 = 18

sum_missing_numbers([17, 16, 15, 10, 11, 12]) ➞ 27
# 13 + 14 = 27

sum_missing_numbers([1, 2, 3, 4, 5]) ➞ 0
# No Missing Numbers (i.e. all numbers in [1, 5] are present in the list)

Notes

The numerical range to consider when searching for the missing numbers in the list is the sequence of consecutive numbers between the minimum and maximum of the numbers (inclusive).

from __future__ import annotations
import unittest
def sum_missing_numbers(numbers: list[int]) -> int:
return 0 # Put your code here!!!
class Test(unittest.TestCase):
def test_1(self):
self.assertEqual(sum_missing_numbers([1, 2, 3, 4, 5]), 0)
def test_2(self):
self.assertEqual(sum_missing_numbers([4, 3, 8, 1, 2]), 18)
def test_3(self):
self.assertEqual(sum_missing_numbers([17, 16, 15, 10, 11, 12]), 27)
def test_4(self):
self.assertEqual(sum_missing_numbers([-1, -4, -3, -2, -6, -8]), -12)
if __name__ == "__main__":
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment