I am a student and learning data structures and algorithms. I am unable to solve or short out this GFG question.
Given an array of size N-1 such that it only contains distinct integers in the range of 1 to N. Find the missing element.
I tried this code but it is not working for all cases.
def MissingNumber(self,array,n):
missingNumber = 0
for i in range(len(array)):
if array[i] !=i+1:
missingNumber = i+1
return missingNumber
Input:
N = 5
A[] = {1,2,3,5}
Output: 4
Please help me out with the code of the best complexity. Thanks in advance.
