Skip to content

Commit

Permalink
missing number problem
Browse files Browse the repository at this point in the history
  • Loading branch information
sankalp5 committed May 17, 2021
1 parent b21f653 commit eb0628b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions algorithms/Python/arrays/missing_number.py
Original file line number Diff line number Diff line change
@@ -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))

0 comments on commit eb0628b

Please sign in to comment.