Find the First Negative Number
EasyPractice library · +10 XPqueuesimulationarrays
Given a sequence of N integers, find the first integer in the sequence that is strictly negative. If no negative integer exists, report that.
Input
The first line contains an integer N, the number of integers in the sequence. The second line contains N integers, separated by spaces.
Output
Print the first negative integer found in the sequence. If no negative integer exists, print the string 'No negative numbers found'.
Constraints
1 <= N <= 1000 -10^9 <= each integer <= 10^9
Time limit 1 s (native code; slower languages get more)Memory 256 MB14 hidden tests
Example 1
Input
5 10 5 -3 8 2
Output
-3
The first negative number is -3.
Example 2
Input
4 1 2 3 4
Output
No negative numbers found
There are no negative numbers in the sequence.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
Example 1 input
5 10 5 -3 8 2
Example 2 input
4 1 2 3 4