Maybe I'm missing something obvious, but this seems like a way to calculate a mode, not a median.
Incidentally this falls in the 'sort an then pick the middle' because the original text says nowhere that is must be a n*log(n) sort and what I described here is essentially the same but with counting sort (and a couple redundant steps removed).