Answer to Question #194982 in Python for J NAGAMANI

Question #194982

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 -1 0 1 2.The largest negative number missing is

-3.

Sample Input 1

-2 -1 0 1 2

Sample Output 1

-3


1
Expert's answer
2021-05-21T02:05:44-0400
N = int(input())
arr = list(map(int, input().split())) 
negative_numbers = list(set([i for i in arr if i < 0]))
negative_numbers.sort(reverse = True)
flag = True
for i in range(len(negative_numbers)):
    if (-i-1 != negative_numbers[i]):
        print (-i-1)
        flag = False
        break
if len(negative_numbers) == 0:
    print (-1)
elif flag:
    print(negative_numbers[len(negative_numbers)-1]-1)

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