forked from OmkarPathak/Data-Structures-using-Python
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathP03_GetMissingNumber.py
More file actions
23 lines (18 loc) · 543 Bytes
/
P03_GetMissingNumber.py
File metadata and controls
23 lines (18 loc) · 543 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Author: OMKAR PATHAk
from Arrays import Array
def findMissing(myArray, n):
n = n - 1
totalSum = (n * (n + 1)) // 2
for i in range(0, n):
totalSum -= myArray[i]
return totalSum
if __name__ == '__main__':
myArray = Array(10)
for i in range(len(myArray)):
myArray.insert(i, i)
myArray.delete(4, 4)
print('Original Array:',myArray)
print('Missing Element:', findMissing(myArray, len(myArray)))
# OUTPUT:
# Original Array: 0 1 2 3 5 6 7 8 9 0
# Missing Element: 4