Problema
Find the position (counting from 0) of the first negative number in the list.
Implement first_negative_index(numbers).
Input
numbers: The list of integers.
Output
Return the index, or -1 if there are no negative numbers.
Vincoli
0 ≤ length ≤ 100,000
Esempi
Esempio 1
Input:
numbers = [4, 0, -2, -7]
Output atteso:
expected = 2
Input:
std::vector<long long> numbers = {4, 0, -2, -7};
Output atteso:
long long expected = 2;
Input:
long[] numbers = new long[] {4, 0, -2, -7};
Output atteso:
long expected = 2;
Spiegazione
-2 at index 2 is the first negative value.
Esempio 2
Input:
numbers = [1, 2, 3]
Output atteso:
expected = -1
Input:
std::vector<long long> numbers = {1, 2, 3};
Output atteso:
long long expected = -1;
Input:
long[] numbers = new long[] {1, 2, 3};
Output atteso:
long expected = -1;
Spiegazione
There are no negative numbers, so the answer is -1.
Riferimenti
Questa sfida è adattata per CodeUtility. Segui la traccia e i vincoli sopra.