Mental Model
We find how many times a number appears in a sorted list by locating its first and last positions.
Analogy: Imagine a row of identical books sorted by title. To count how many copies of one title are there, find the first copy and the last copy, then count all in between.
Array: [1, 2, 2, 2, 3, 4, 5]
↑ ↑
first last
occurrence occurrence