"""Linear search.

Idea
----
Check every element from left to right until you find the target. It is the
only option when the data is unsorted and has no index.

Complexity
----------
Time:  O(n) worst/average, O(1) best
Space: O(1)
"""

from collections.abc import Sequence
from typing import TypeVar

T = TypeVar("T")


def linear_search(items: Sequence[T], target: T) -> int:
    """Return the index of the first ``target`` in ``items`` or -1."""
    for i, value in enumerate(items):
        if value == target:
            return i
    return -1
