Answer to Question #195025 in Python for Ramesh

Question #195025

Largest Missing Negative Number


You are given an unsorted array A of N integers. You have to find


the largest negative integer missing from the array.


Input


The first line contains N space-separated integers of A


Output


The output contains N space-separated integers representing the number of people as mentioned above.


Explanation


Given A-2-1012


The largest negative number missing is 3


Sample Input 1

-2 -1 0 1 2

Sample output 2

-3

sample input 2

-11 -10 -12

Sample output 2

-1


1
Expert's answer
2021-05-18T13:01:33-0400
def largest_negative(l:list):


	i = -1
	while True:
		if i not in l:
			return i
		i -= 1


while True:
	try:
		A = list(map(int,input().split()))
	except ValueError:
		print('incorrect input')
		continue
	print(largest_negative(A))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS