Find First and Last Position — binary search, twice
One binary search finds the first index that is ≥ the target — the first occurrence, provided the value there actually equals the target. A second finds the first index that is > the target; one step before it is the last occurrence.