  We characterize the functions $f\colon [0,1] \longrightarrow [0,1]$ for which
there exists a measurable set $C\subseteq [0,1]$ of positive measure satisfying
$\frac{|C\cap I|}{|I|}<f(|I|)$ for any nontrivial interval $I \subseteq [0,1]$.
As an application, we prove that on any $C^1$ curve it is possible to construct
a Lipschitz function that cannot be approximated by Lipschitz functions
attaining their Lipschitz constant.
