Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Find First Negative

Search a list to find the index of the first negative number.

Python practice8 minLoops & IterationBeginnerLast updated March 15, 2026

Problem statement

Given a list of integers, return the index (0-based) of the first negative number. If there are no negative numbers, return -1.

Task

Use iteration to locate the first element satisfying a condition and return its index.

Examples

Negative in the middle

Input

find_first_negative([1, 2, -3, 4])

Output

2

The first negative number is -3 at index 2.

Input format

A list of integers.

Output format

An integer representing the index of the first negative, or -1 if none.

Constraints

Do not use built-in functions that directly find index by predicate. Aim for O(n) time and O(1) extra space.

Samples

Sample 1

Input

find_first_negative([-1, 2, -3])

Output

0

The very first element is negative, so return index 0.