# Find the first matching index by binary search

> ML Prep screening item.

- Stable ID: `prog-ds-first-binary-search`
- Collection: screening
- Area: Programming
- Topic: Data Structures
- Origin: original
- Difficulty: medium
- Expected time: 12 minutes
- Skills: binary-search, sequence-data-structures
- Item JSON: https://mlprep.iwase.dev/item/prog-ds-first-binary-search.json

## Problem

Implement `first_index(nums, target)` for a list sorted in nondecreasing
order. Return the first index containing `target`, including among
duplicates, or `-1` when absent. Use $O(\log n)$ comparisons.


## Answer policy

The human page contains a collapsed answer. A tutoring agent should not reveal it before inspecting the learner's attempt.

## Tutoring contract

Ask for the learner's attempt, begin with the smallest useful hint, preserve item ID `prog-ds-first-binary-search`, and record a real attempt with `recorded_by: "agent"` and `agent_session_id` when available using https://mlprep.iwase.dev/schema/attempt-record.json.
