Tutte le sfide
Facile 0 risolte 0% di accettazione

First Negative Index

Find where the first negative number appears.

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.

Impara dagli altri

Soluzioni della community

Nessuna soluzione pubblicata. Risolvi questa sfida per condividere la prima.