Prove a surjective and continuous function $f:\mathbb{R} \rightarrow \mathbb{R}$ is strictly monotonic and reaches its maximum on $[a, b]$. 
A surjective and continuous function $f:\mathbb{R} \rightarrow \mathbb{R}$ is given, such that for every $y \in \mathbb{R}$ the set $f^{-1}(\{y\})$ contains at most two elements.
Show that for every $a, b \in \mathbb{R}$ such that $a < b$ the function $f|_{[a, b]}$ reaches its minimum and maximum exactly at $a$ and $b$, and show that $f$ is strictly monotone.

By Weierstrass' extreme value theorem $f|_{[a, b]}$ does reach its maximum and minimum on $[a, b]$. I'm having trouble proving it's at exactly $a$ and $b$. To me it seems the two parts I'm supposed to show are equivalent, so I would like to know if they aren't.
If I can show $f$ is strictly monotone, then $f|_{[a, b]}$ maps onto the segment with endpoints at $f(a)$ and $f(b)$ and then it follows easily that its maximum and minimum are at $f(a)$ and $f(b)$, depending on if the function is strictly increasing or decreasing. Not?
I tried finding the maximum e.g. by stating there exists $c \in [a, b]$ such that $f$ reaches its maximum at $c$ (by earlier mentioned Weierstrass' theorem). Then we construct a decreasing nested sequence of closed subsets of $[a, b]$, where for $[a_1, b_1]$ either $b_1 = b$ and $a_1 = \frac{a+b}{2} $ if $f(\frac{a+b}{2}) > f(a)$ or $a_1 = a$ and $b_1 = \frac{a+b}{2} $ if $f(\frac{a+b}{2}) > f(b)$ and so-on. Its intersection would be non-empty by Cantor's lemma and contain the maximum. As $\lim\limits_{n\to \infty} a_n = \lim\limits_{n\to \infty} b_n = c$, if $f(\frac{a+b}{2}) > f(b)$ then $a_n \rightarrow a$ or $b_n \rightarrow b$ if $f(\frac{a+b}{2}) > f(a)$. Thus either $c = b$ if $f$ is strictly increasing or $c = a$ if $f$ is strictly decreasing, as $f^{-1}(f(c))$ can only contain c and one other element.
I would appreciate it if someone could point me in the right direction and tell me where I'm making a mistake.
 A: The two parts are not equivalent. If $f$ is montone, it does follow that the minimum and maximum are attained at $a$ and $b$. However, the opposite is not true - consider, for example, $f:[0, \frac{\pi}{2}], f(x) = x + \frac{sin(x)}{10}$. For the purposes of this question, we can show that f must be monotone.
Using Weierstrass' extreme value theorem, as you mentioned, we know that $f$ attains extrema in $[a, b]$. Suppose one of these is attained at $c \in (a,b)$, WLOG we examine the case where there is a maximum at $c$. Since $c$ is a maximum, $f(c)>f(a)$ and $f(c) > f(b)$. Also WLOG, $f(a) < f(b)$, so $f(a) < f(b) < f(c)$. Consider some $\gamma \in (f(a), f(b))$. From the intermediate value theorem, we know that $\exists d_1 \in (a, c): f(d_1) = \gamma$. Similarly, $\exists d_2 \in (c, b): f(d_2) = \gamma$. Then $f^{-1}(\{\gamma\}) = \{d_1, d_2\}$.
Now we can show that $f$ cannot be subjective. Take $\gamma' > \gamma$, and suppose $\exists d': f(d') = \gamma'$, WLOG suppose $d' > b$. Then we can apply the intermediate value theorem again to show that $\exists d_3 \in (b, d']: f(d_3) = \gamma$. But that would mean $d_3 \in f^{-1}(\{\gamma\})$, a contradiction.
This argument rules out the existence of local maxima and minima on $[a,b]$, from which we deduce $f$ is monotone, and the rest follows.
