Largest Missing Negative Number
You are given an unsorted array
The first line contains
The output contains
Given
A = -2 -1 0 1 2.The largest negative number missing is
-3.
Sample Input 1
-2 -1 0 1 2
Sample Output 1
-3
Sample Input 2
-11 -10 -12
Sample Output 2
-1
s = input()
A = [int(w) for w in s.split() if int(w) < 0]
A.sort(reverse=True)
x = -1
for i in range(len(A)):
if x > A[i]:
break
x = A[i] - 1
print(x)
Comments
Leave a comment