Suppose you have a particle moving in 1 dimension.
There's an acceleration $a(t)$, a velocity $v(t)$ and a total distance traveled, $s$.
The particle starts and ends at rest.
The goal is to travel $s$ distance in time $T$, while minimising $$\int_0^{T}{a(t)^2 dt}$$
How do you find that function?
This kind of questions may be solved by standard techniques of calculus of variations, and in particular the Euler-Lagrange equations. Here I derive the solution in an informal manner, which can actually be made rigurous.
Suppose $f(t)$ determines the position of your particle at time $t$. Then you are asking to find $f$ satisfying $$f(0) = 0, \quad f(T) = s, \quad f'(0) = 0, \quad f'(T) = 0$$ and minimizing $\int (f''(t))^2 \, dt$. The trick is that if the minimizer $f$ really exists and is unique, then if we perturb it a little we will make the functional $\int (\cdot)^2\, dt$ actually bigger. So if we substitute $f$ by $f + \epsilon g$ where $g$ is any function for which $f + \epsilon g$ still satisfies the constrains then $$ \frac{\partial}{\partial \epsilon} \int (f''(t) + \epsilon g''(t))^2 \, dt \Bigg|_{\epsilon = 0} = 0.$$ That is so because the integral must have a minimum as $\epsilon$ varies when $\epsilon = 0$.
Note we can take by $g$ any function satisfying $$g(0) = 0, \quad g(T) = 0, \quad g'(0) = 0, \quad g'(T) = 0.$$ Assuming we can differentiate under the integral sign, we obtain $$0 = \int f''(t) g''(t) \, dt = -\int f'''(t) g'(t) \, dt.$$ In the last step we have used integration by parts.
At this point let us reformulate what we have: calling $h = g'$ we have deduced that for any $h$ satisfying $$\int h(t) \,dt = 0, \qquad h(0) = h(T) = 0$$ we must have $$\int f'''(t) h(t)\, dt = 0.$$ Fix any two points now $0 < a < b < T$. We some small $\delta > 0$ can construct a function $h$ which vanishes on $[0, a- \delta] \cup [a + \delta, b - \delta] \cup [b + \delta, T]$, is positive and has unit mass on $[a - \delta, a + \delta]$ and is negative and has unit mass on $[b-\delta, b + \delta]$. This function satisfies all of the above, and furthermore, as we make $\delta$ increasingly small it is not difficult to check that $$0 = \int f'''(t) h(t) \, dt \approx f'''(a) - f'''(b).$$ In the limit $\delta \rightarrow 0$ this becomes an identity and since $a$ and $b$ were generic points we deduce that $f'''$ must be constant, or equivalently $f$ is a third degree polynomial.
Therefore $f(t) = a t^3 + bt^2 + ct + d$. Now the restrictions on $f$ shown at the beginning determine all four coefficients, and the candidate is $$f(t) = -2 s T^{-3} t^3 + 3s T^{-2} t^2.$$
It is important to note an important caveat in the previous proof sketch: we have not proved a minizer exist and is smooth, but if it does it must be the $f$ we have found.