TITLE: Show that there's no continuous function that takes each of its values $f(x)$ exactly twice.
QUESTION [17 upvotes]: I need to prove the following:
There's no continuous function $f:[a,b]\to \mathbb{R}$ that takes each of its values $f(x)$, $x\in [a,b]$  exactly twice.
First of all, I didn't understand the question. For example $x^2$ takes $1$ twice, in the interval $[-1,1]$. Is it saying that it does not occur for all $x$ in the interval? But what about $f(x) = c$? Is it saying that it does not occur only exactly $2$ times, then? I have no idea about how to prove it. I know that for $f(x)$ such that $f(a)<f(x)<f(b)$, if $f$ is continuous then there is a $c\in [a,b]$ such that $f(c) = f(x)$.
Now, there's the following proof in my book and I really wanted to understand it, instead of just getting a new proof
Since the interval $[a,b]$ has only $2$ extreme points, then the maximum or minimum of $f$ must be in a point $c\in int([a,b])$ and and in another point $d\in [a,b]$. Then, there exists $\delta>0$ such that in the intervals $[c-\delta, c), (c,c+\delta)$ (and if $d$ is not extreme of $[a,b]$, $[d-\delta, d]$) the function takes values that are less than $f(c) = f(d)$. Let $A$ be the greatest of the numbers $f(c-\delta), f(c+\delta), f(d-\delta)$. By the intermediate value theorem, there are $x\in [c-\delta, c), y\in (c, c+\delta]$ and $z\in [d-\delta, d)$ such that $f(x)=f(y)=f(z)=A$. Contradiction. 
Well, why the last part? Why is it that I can apply the intermediate value theorem to these values? For example, $<f(c-\delta)<p<f(c)$, then by the theorem I know that there exists $m\in [c-\delta, c)$ such that $f(m) = p$. Same for the other intervals. But what guarantees thhat the greatest of the values between  $x\in [c-\delta, c), y\in (c, c+\delta]$ will be inside the intervals $[c-\delta), c), (c,c+\delta), [d-\delta, d)$?

REPLY [2 votes]: I think the following way may be simpler.
Translation of the function doesnot change the generality. So assume that by translating f(x) we make it crosses the $x$ axis. Let denote it by $\tilde f$
By the hypothesis, $\exists x_1,x_2\in \mathbb R$ such that $\tilde f(x_1)=0=\tilde f(x_2)$ with $x_1<x_2$. Moreover there is no another point $x\in\mathbb R$ that $\tilde f(x)=0$.
So either $\tilde f\le 0$ or $\tilde f\ge 0$  on $[x_1,x_2]$ by extreme value theorem $\tilde f$ takes one of its extreme values at interior of $[x_1,x_2]$, according to its sign. And it is unique so we get contradiction.
Why is one of the extremas on $[x_1,x_2]$ unique?
i) Inductive geometrically: If we were to draw horizontal lines from $x$ axis since the hyphothesis states graph should intersect with these lines exactly twice, until to maxima or minima, there may be no problem but at these extremas the horizontal line can only intersects once. (This explanation is only intuitional, see the figure below)
ii) More formally (we emphasize the idea in formal way to elaborate the idea), WLOG assume $\tilde f\ge 0$ and we have minimum at boundaries, denote first maximum $c_1$. Assume we have another maximum at $x=c_2$. Since $\tilde f$  is continuous at $c_1,c_2$ there exist two closed neighborhood $\delta_1,\delta_2$, now consider $\delta=min\{\delta_1,\delta_2\}$. Observe $\tilde f(\delta_{c_1})=[c^{*}_1, \tilde f(c_1)=M]$ and $\tilde f(\delta_{c_2})=[c^{*}_2,\tilde f(c_2)=M]$
So in the $y$ axis closed interval $[min\{c^{*}_1,c^{*}_2\},M]$ every point corresponds to $4$ different value in $x$ axis.
Edit: About geometric interpretation of uniqueness of one of the extremas.