I have the following problem:
Suppose that two teams play a series of games that end when one of them has won $i$ games. Suppose that each game played is, independently, won by team $A$ with probability $p$. Find the expected number of games that are played when $i=2$. Also show that this number is maximized when $p=\frac12$.
Here is the solution:
I have trouble understanding the part of solution that demonstrate that this number is maximized when $p = \dfrac{1}{2}$.
How do you know that $\dfrac {dE\left( x\right) }{dp}=0$?

Usually you find critical point x of a differentiable function when you set the derivative equal to zero. You want to find the maximum of $\mathbb E(X)$. When you solve the equation $\frac{d \mathbb E(X)}{dp}=0$ you get the $p$-value of a critical point (saddle point, relative maximum, relative minimum). Let´s call it $p^*$. Now you have to evaluate if this is a relative maximum.
If $\frac{d \mathbb E^2(X)}{dp^2}(p^*)<0$ you have found the relative maximum. Since $\lim\limits_{p \to \infty} \mathbb E(X)=\lim\limits_{p \to -\infty} \mathbb E(X)=-\infty$ the relative maximum is an absolute maximum.