Two boundaries, three counts.
transcript
Two million sorted payments. How many are smaller than four? How many equal, and how many larger? Do not read the whole list.
A sorted list has three blocks. Smaller first. Then the equal ones. Then the larger ones.
Two boundaries split the blocks. The fours start at position one. That is the lower bound. The larger ones start at four. That is the upper bound.
Smaller is the lower bound. Equal is upper minus lower. Four minus one is three. Larger is n minus upper. Seven minus four is three.
What if the amount is missing? Both bounds meet at one position. That is where it would be inserted. And the count is zero.
Each search is a binary search. Two million payments need at most forty-two checks. The scan needs two million. Fifty thousand amounts need about two million checks. The scan would need a hundred billion.
Find both boundaries, and subtract. Full breakdown in the lecture.