Is there is any example of continuous bounded function on $\mathbb{R}$ which attains ‘either’ maximum ‘or’ minimum on $\mathbb{R}$ but not both.

continuityreal-analysis

I need to find example of continuous bounded function on $\mathbb{R}$ which attains 'either' maximum 'or' minimum on $\mathbb{R}$ but not both.

My attempt:

First of all, is such function exists? (How)? If it exists then isn't it will contradict extreme value theorem?

Is $f(x)=\frac{1}{x^2+1}$ for $x\in\mathbb{R}$ works?

Best Answer

Let $f(x)=e^{-x}$ for $x \geq 0$ and $f(x)=1$ for $x<0$. Then $f$ is continuous and bounded. Its maximum value $1$ is attined but its infimum $0$ is not attained.