missing number problem

pull/310/head
Sankalp Sharma 2021-05-17 10:43:53 +05:30
parent b21f653195
commit eb0628b0e7
1 changed files with 15 additions and 0 deletions

View File

@ -0,0 +1,15 @@
"""
Algorithm Type: Array Traversal
Time Complexity: O(n)
"""
numbers = [1, 2, 4, 3, 6, 7, 9, 8, 10]
n = 10
def missing_number(numbers, n):
s = sum(numbers)
expected_s = (n*(n+1))//2 #for C++ or similar, keep in mind expected_s can overflow MAX INT limit.
return expected_s - s
if __name__ == "__main__":
print(missing_number(numbers, n))