I need help with this problem:
If $X, Y$ are random variables in the interval $[a,b]$ then $\vert\mathrm{cov}(X,Y)\vert\leq\dfrac{(b-a)^2}{4}$
By definition
$$\mathrm{cov}(X,Y) = E[(X-E(X))(Y-E(Y))]=E(XY)-E(X)E(Y).$$
If $X-E(X) \leq \dfrac{(b-a)}{2}$ I finish, but this is not necessary true.
As pointed out by the comment above, notice that
$$\vert\mathsf{Cov}(X,Y)\vert\leq\sqrt{\smash[b]{\mathsf{Var}(X)\mathsf{Var}(Y)}}$$
and that
$$\mathsf{Var}(X)\leq\mathsf{E}\left[\left(X-\frac{a+b}{2}\right)^2\right]\leq\frac{(b-a)^2}{4}.$$
Here we utilized the simple observation that, if $\mathsf{E}[X^2]<\infty$, then $\mathsf{Var}(X) \leq \mathsf{E}[(X-c)^2]$. This easily follows by studying the minimum of $\mathsf{E}[(X-c)^2]$, which is a quadratic polynomial in $c$.