Optimal Hypothesis Selection in (Almost) Linear Time