Show that there's no continuous function that takes each of its values $f(x)$ exactly twice.
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.
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$.
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.