Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions solutions/sol18.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#Himanshu Nachane (@Himanshu1495)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you rename this file to just 18.py please?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@songz, I tried keeping it 18.py but then I found out that Python files should not start with a number for the exact same reason. It would be good to keep the file name as sol18.py or anything which starts with a string.

'''return missing number in an input array of consecutively increasing numbers.

i: [5,6,8,9]
o: 7
'''

def missing_num(arr):
first_element = arr[0]
last_element = arr[-1]
new_sum = 0
for x in range(first_element,last_element+1):
new_sum += x
return new_sum - sum(arr)



14 changes: 14 additions & 0 deletions test/18.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import sys
sys.path.insert(0,'../solutions/')
from sol18 import missing_num
import unittest

class MyTest(unittest.TestCase):
def test1(self):
self.assertEqual(missing_num([10,11,12,14,15,16]),13)
def test2(self):
self.assertEqual(missing_num([125,126,128,129,130]),127)
def test3(self):
self.assertEqual(missing_num([1125,1127,1128,1129,1130]),1126)

unittest.main()