Let $f:\mathbb{R}\to \mathbb{R}$ be a bounded continuous function. Suppose for any $y\in \mathbb{R}$, $f^{-1}(\{y\})$ is the empty set or a finite set. Then $f$ is uniformly continuous.

My idea :If $f$ is not uniformly continuous, there exists $a_n, b_n$ and $\epsilon $ s.t., $|a_n-b_n|\leq \frac{1}{n}$ $|f(a_n)-f(b_n)|>\epsilon$ . $f$ is bounded, so I can take convergence subsequence. But I don't know how to use cardinality of $f^{-1}(\{y\})$


Take $\epsilon>0$. Consider the sequence $f(1),f(2),...$ which has a limit point $C$ by Bolzano-Weierstrass. Since $f^{-1}(C)$ is finite/empty and $f$ is continuous, it cannot cross $C$ infinitely many times, so assume WLOG that $f(x)<C$ for all sufficiently large $x$. Similarly $f$ can't cross $C-\epsilon$ infinitely many times, so for all large enough $x$ we have $f(x)\in (C-\epsilon,C)$ (as $C$ is a limit point, so there are infinitely many $f(x)$ in that range). Say this holds for $x>B$, which means $|f(x)-f(y)|<\epsilon$ for $x,y\in (B,\infty)$.

We can do a similar thing to find $A$ such that $|f(x)-f(y)|<\epsilon$ for $x,y\in (-\infty,A)$, and note that $[A-1,B+1]$ is compact, so $f$ is uniformly continuous on that interval, so we can find $\delta<1$ such that $|f(x)-f(y)|<\epsilon$ for $|x-y|<\delta$. Therefore $f$ is uniformly continuous on $\mathbb R$.