Given a continuous function on [0,1], find all constants such that the distance of f from the set of all constant functions is minimum. Let us consider the space $C[0,1]$ endowed with the supremum norm and $f\in{C[0,1]}$. Let K be the set of all constant functions $g : [0,1] \rightarrow \mathbb{R}$ and consider the set $A=\{ g\in{K} : ||f-g||_{\infty}=d(f,K) \}$, where $d(f,K)= \inf\{||f-g||_{\infty}:g\in{K} \}$. Find $A$.
My attempt: If $f\in{K}$, then $A=\{f\}$.
If $f\notin{K}$, consider $m=\min{f(t)}$ and $M=\max{f(t)}$ where $m<M$. Let $g\in{K}$. Then, $g(t)=c$ for every $t\in{[0,1]}$ for some $c\in{\mathbb{R}}$.
If $c\leq m \implies ||f-g||=M-c\ge M-m$.
If $c\ge M \implies ||f-g||=c-m\ge M-m$.
If $m\leq c\leq M \implies ||f-g||=\max \{M-c,c-m \}\ge \frac{M-m}{2}$
In any case $d(f,K)\ge \frac{M-m}{2}$, but I cannot think of such constant such that $||f-c||=\frac{M-m}{2}$ and thus I cannot conclude a "probable" equality. Thank you in advance.
 A: Set $h(x)=c=\frac{M+m}{2}$ to be the mean of maximum and minimum of $f$. Then your set will be $A=\{h\}$. Check all requirements:
First show $\|f-h\|\leq\frac{M-m}{2}$ by contradiction.
If we had $\|f-h\|>\frac{M-m}{2}$ then either (a) there is some $x\in[0,1]$ such that $f(x)-h(x)>\frac{M-m}{2}$ or (b) there is some $x\in[0,1]$ such that $h(x)-f(x)>\frac{M-m}{2}$. Wlog assume (a). Then since $h(x)=\frac{M+m}{2}$ we had:
$$
f(x)-h(x)>\frac{M-m}{2} \Leftrightarrow
$$
$$
f(x)-\frac{M+m}{2}>\frac{M-m}{2} \Leftrightarrow
$$
$$
f(x)>\frac{M-m}{2}+\frac{M+m}{2} \Leftrightarrow
$$
$$
f(x)>M.
$$
This would contradict the choice of $M=\max\{f(t):t\in[0,1]\}$. Similarly (b) would give a contradiction to $m$ being the minimum.
Since $f$ is continuous, maximum (and minimum) are attained somewhere on $[0,1]$ e.g. at $x_M$. Then
$$
\|f-h\|\geq
$$
$$
|f(x_M)-h(x_M)|=
$$
$$
\left|M-\frac{M+m}{2}\right|=
$$
$$
\left|\frac{M-m}{2}\right|=
$$
$$
\frac{M-m}{2}.
$$
This shows combined with the paragraph above that $\|f-h\|=\frac{M-m}{2}$ and therefore $h\in A$.
Assume there was another function $h\neq k\in A$. It would be of the form $k(x)=c\neq \frac{M+m}{2}$. Either (a) $c<\frac{M+m}{2}$ or (b) $c>\frac{M+m}{2}$. Wlog assume (a). In this case $M\geq \frac{M+m}{2}>c$. With the maximum position $x_M$ from above we had:
$$
\|f-k\|\geq
$$
$$
|f(x_M)-k(x_M)|=
$$
$$
\left|M-c\right|=
$$
$$
M-c=
$$
$$
\left(M-\frac{M+m}{2}\right)+\left(\frac{M+m}{2}-c\right)>
$$
$$
\frac{M-m}{2}+0=
$$
$$
\frac{M-m}{2}.
$$
Case (b) works out the same way with minimum replacing maximum.
But when $\|f-k\|>\frac{M-m}{2}=\|f-h\|$ this contradicts $k\in A$. So there is no other function in $A$ than $h$.
