Does there exist a continuous function $f: \mathbb{R} \to \mathbb{R}$ that takes each value in $\mathbb{R}$ exactly two times? Does there exist a continuous function $f: \mathbb{R} \to \mathbb{R}$ that takes each value in $\mathbb{R}$ exactly two times?
im not getting the red lines as how can postive value achieved 3 times .
Can anybody elaborate in detail  as im not getting in my head.
thanks u
 A: Say that $c \in (a,b)$ is where $f$ achieves its positive maximum $f(c) = M$ on $[a,b]$. Then there is some $x\in (a,c)$ such that $f(x) = M/2$. Similarly, there is some $y\in (c,b)$ such that $f(y) = M/2$ by the intermediate value theorem.
Since $f$ is positive in $(-\infty,a)$ and negative in $(b,+\infty)$, there is some point $w\in (-\infty,a)$ such that $f(w) = 2M$ because $f$ is surjective. By the intermediate value theorem, there is a point $z \in (w,a)$ such that $f(z) = M/2$.
But then we have produced three distinct points where $f(z) = f(x) = f(y) = M/2$.
A: Let $m$ be the maximum point on $[a,b]$ where $f(m)=M>0$.
The left interval is positive, let $c<a$ and $f(c)=W>0$
Let $T= \min(M,W)$. 
Apply intermedidate value theorem on $(c,a)$, we can find a point in that interval attaining value $\frac{T}2$.
Apply intermedidate value theorem on $(a,m)$, we can find a point in that interval attaining value $\frac{T}2$.
Apply intermedidate value theorem on $(m,b)$, we can find a point in that interval attaining value $\frac{T}2$.
Hence it is achieved $3$ times.
A: Choose any number $y \in (0, \max_{[a, b]} f)$. Then $f(x) = y$ has at least two solutions on $(a, b)$ as a consequence of the intermediate value theorem.
Now because $f$ is nonnegative on $(-\infty, a)$ and blows up, continuity guarantees that $f(x) = y$ has at least one solution on this interval too. 
So we have three total.
If you haven't yet, you really need to draw a graph of this scenario.
