Show that there's no continuous function that takes each of its values $f(x)$ exactly twice. 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)$?
 A: Suppose $f:[0,1]\to\mathbb{R}$ takes each of its values exactly twice.   Consider the self-map FLIP of the interval $[0,1]$ switching the two points where the values of the function are equal.  This FLIP a continuous map without fixed points.  But any self-map of the closed interval must have a fixed point by (the trivial one-dimensional case of) Brouwer's fixed point theorem. This proves that there is no such function $f$.
A: Hint: you don't need to use continuity, only the Darboux (intermediate value) property. Look at the minimum and maximum value of $f$ in the interval. 
Notice that they have to be distinct (otherwise it is clearly false), and then consider the relative placement of the four points where the extreme values are attained, and using the Darboux property argue that in each cases, some values will be attained at least three times.
A: Given such a function, $[a,b]$ is partitioned into uncountably many pairs $\{x_1,x_2\}$ with $f(x_1)=f(x_2)$. Can two pairs $\{x_1,x_2\}$ and $\{x_3,x_4\}$ overlap? In such a acase we would have wlog $x_1<x_3<x_2<x_4$. Pick $c$ between $f(x_1)$ and $f(x_2)$. By the Intermediate value property, there exists $\xi\in(x_1,x_3)$ with $f(\xi)=c$. But such $\xi$ also exists in $(x_3,x_2)$ and in $(x_2,x_4)$, contradicting the special property of $f$. We conclude that two distinct pairs $\{x_1,x_2\}$ and $\{x_3,x_4\}$ can only be nested. Then the intersection of the nested closed intervals with these pairs as endpoints is non-empty and contains a point $\bar x_1$ that cannot occur in a pair $\{\bar x_1,\bar x_2\}$.
A: 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.

A: Earlier I had linked my question with this one of yours and it was closed as a duplicate. But you are not so much interested in knowing a proof of the result, but rather you are interested in understanding the proof given in your textbook. The following answer is thus an explanation for the proof given in your textbook.
The solution given in your textbook is very concise and does not give all the details. Since $f$ is continuous on $[a, b]$ its range is also a closed interval $[m, M]$. The solution assumes that $m < M$ otherwise $f$ is a constant and does not meet hypotheses of the question.
Next it says that the value $M$ is taken at two distinct points $c, d$ and says that one of them say $c \in (a, b)$ and $d \in [a, b]$. It is however possible that both $c, d$ are endpoints of $[a, b]$. This is not mentioned or considered in the solution. Anyway proceeding with the textbook solution let $c \in (a, b), d \in [a, b]$ and $f(c) = f(d) = M$. Moreover $f(x) < M$ for all $x \in [a, b], x \neq c, x\neq d$.
Next the solution proposes the existence of $\delta > 0$ such that $f(x) < M$ for all $x \in [c - \delta, c) \cup (c, c + \delta)$. Further if $d \neq a$ then we also have $f(x) < M$ for all $x \in [d - \delta, d)$ (there is a typo in the solution where it writes $[d - \delta, d]$ instead of $[d - \delta, d)$). All these statements are true by the last sentence of previous paragraph. And note that the solution does not handle the case $d = a$. Now it considers $$A = \max(f(c - \delta), f(c + \delta), f(d - \delta))$$ BTW out of these values $f(c - \delta), f(c + \delta), f(d - \delta)$ at max two can be equal. If $B$ is the minimum of these values then $B < A < M$ and thus by intermediate value theorem $A$ is attained once in each of the three intervals $[c - \delta, c], [c, c + \delta]$ and $[d - \delta, d]$ and thus $f$ takes the value $A$ at three distinct points $x, y, z$. That these three points are distinct follows from the fact that $\delta$ can be chosen so that $(c - \delta), (c, c + \delta)$ and $(d - \delta, d)$ are pairwise disjoint. This is contrary to the hypotheses in the question. This completes the proof.
The solution needs to address the two cases which are left out:


*

*The case when $c, d$ are both the end points of $[a, b]$.

*The case when $d = a$ and $c \in (a, b)$. Here we consider $[d, d + \delta]$ and argue like your textbook solution.


For the first case when $c, d$ are endpoints so that for example $c = a, d = b$, we necessarily need to consider the points $p, q \in (a, b), p < q$ where $f$ takes minimum value $m$. Thus we have $f(p) = f(q) = m < M = f(a) = f(b)$. Note further that all the values of $f$ in $(p, q)$ are greater than $m$ and hence if $M'$ is maximum value of $f$ in $[p, q]$ then $m < M' < M$. And suppose $M'$ is attained at $r \in (p, q)$. Let $K$ be any number such that $m < K < M' < M$. Then by intermediate value theorem $f$ takes the value $K$ once in each of the intervals $(a, p), (p, r), (r, q), (q, b)$ and this contradicts the hypotheses.
