Skip to content

Commit eab82f5

Browse files
committed
Array Programs: Finding missing numbers
1 parent 2731ebc commit eab82f5

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Arrays/P03_GetMissingNumber.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Author: OMKAR PATHAk
2+
3+
from Arrays import Array
4+
5+
def findMissing(myArray, n):
6+
n = n - 1
7+
totalSum = (n * (n + 1)) // 2
8+
for i in range(0, n):
9+
totalSum -= myArray[i]
10+
11+
return totalSum
12+
13+
if __name__ == '__main__':
14+
myArray = Array(10)
15+
for i in range(len(myArray)):
16+
myArray.insert(i, i)
17+
myArray.delete(4, 4)
18+
print('Original Array:',myArray)
19+
print('Missing Element:', findMissing(myArray, len(myArray)))
20+
21+
# OUTPUT:
22+
# Original Array: 0 1 2 3 5 6 7 8 9 0
23+
# Missing Element: 4

0 commit comments

Comments
 (0)