I provided a solution in C++ that solves the problem in 0ms, try it!
The first observation is that there is no reason to pass over the data
twice. The classic solution sorts the data in the first pass and then
counts the number of targets indexes in the second pass.