When is maximising
$$\int_a^b f(x) \text{d}x$$
the same as maximising $f(x)$?
Context: I was trying to find the most probable location of an electron in the ground state hydrogen atom, where the wavefunction is $\text{exp}(-r/a_0)$, and hence the probability density is $\text{exp}(-2r/a_0)$. The probability is therefore proportional to
$$\iiint e^{-\frac{2r}{a_0}}\text{d}^3{\bf r}.$$
Since in spherical coordinates, the volume of a spherical shell is $4\pi r^2 \text{d}r$, I am told that to maximise the probability, I should maximise $r^2 \text{exp}(-2r/a_0)$. However, I seem to be maximising the integrand, not the integral, here. If $\text{d}P \propto r^2 \text{exp}(-2r/a_0) \text{d}r$, is $\text{d}P/\text{d}r$ not just $r^2 \text{exp}(-2r/a_0)$?
In order to make sense of this, maximizing an integral, we really need to introduce another parameter: $$I(t)=\int_a^b f(t,x)\,dx$$ Now, clearly, $$\max_t I(t)\le \int_a^b \max_t f(t,x)\,dx$$ We have equality when that $\max_t f(t,x)$ occurs at the same $t$ for all $x$. If we can maximize the function simultaneously for all $x$, then integrating that maximum gets us the maximum integral. If we can't, then we'll have to do something else.
For example, if that was $I(t)=\int_{-1}^1 tx\,dx$ for $-2\le t\le 2$, then the maximum of $f$ occurs at $t=2$ for $x>0$ and at $t=-2$ for $x<0$ - not the same place. The value of $I(t)$ is identically zero, while $\int_{-1}^1 \max_t(tx)\,dx=\int_{-1}^1 2|x|\,dx=2$.
Now, your "context"? That's really not the same thing - it's not about maximizing an integral. The "most probable location" should be the point at which the probability density is maximized (the origin). The "most probable distance", which seems to be what you actually want here, comes from transforming that spatial density function into a linear density function $f(r)=4\pi r^2\exp(-2r/a_0)$, the probability density for distance from the origin. And, again, we're just looking for where that density is largest.