data-structures · beginner · ~15 min

Linear search

Scan an array for a value.

Challenge

Implement int linear_search(const int *a, int n, int target) returning the index of target, or -1 if absent.

Starter code

int linear_search(const int *a, int n, int target) {
    /* TODO */
    return -1;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.