I am trying to solve the following problem:
Let's say a "frog" is jumping on the numberline starting at $0$, jumps randomly on every integer from $1,\dots,n$ and then comes back to 0. What is the longest possible distance it can cover for a given $n$?
As an example the case where $n=3$, the longest walk the "frog" can take can be expressed as follows: $$0\to2\to3\to1\to0$$ the maximal covered distance in this case is $2+|2-3|+|3-1|+1=8$. In general, I will express these random walks as $0a_1a_2\dots a_n0$ where each $a_i\in{1,\dots, n}$ is distict, the walk in the example can then be expressed as $02310$. The problem asks to maximize the quantity $L:=a_1+|a_1-a_2|+\dots +|a_{n-1}-a_n|+a_n$.
I was not able to find the complete proof of this result, however I was able to find an equivalent problem, that could possibly be easier to solve. I am going to explain my proof with $n=5$, but the same logic can be applied for any $n$. I came up with the following diagramm, here the $y$ coordinates of the points are the elements of the sequence from $1,...,5$ from left to right, the corresponding sequence in the example is $0415230$. I then proceeded to calculate the area under the graph in two ways. First I calculated the area as the sum of areas of the green triangles, $A_1$, and the red rectangles, $A_2$, on the diagramm. The calculation is a bit complicated to explain but can be seen from the diagramm (in every triangle one of the legs is equal to 1, and so is one of the sides in every rectangle). In general: $$A_1=\frac{1}{2}⋅ 1⋅a_1+\frac{1}{2}⋅1⋅|a_1-a_2|+\dots+\frac{1}{2}⋅1⋅a_n=\frac{1}{2}L$$ and $$A_2=a_1+\min(a_1,a_2)+\min(a_2,a_3)+\dots+a_n:=B$$ So the overall area under the graph is equal to $A=A_1+A_2=\frac{1}{2}L+B$. And now we calculate the area the second way using the trapesoids as seen here. Then: $$A=\frac{a_1}{2}+\frac{a_1+a_2}{2}+\dots+\frac{a_{n-1}+a_n}{2}+\frac{a_n }{2}=$$ $$=a_1+a_2+a_3+\dots + a_n=\frac{n(n+1)}{2}$$ So we get $$\frac{1}{2}L+B=\frac{n(n+1)}{2}$$ for any randomly chosen sequence of $a_i$'s. If we rearrange for $L$ we get $L=n(n+1)-2B$. So the problem of maximizing $L$ can now be restated as the problem of minimizing $B$, where $$B:=a_1+\min(a_1,a_2)+\min(a_2,a_3)+\dots+a_n$$ Other than that I found the maximal values of $L$ for $n=1,2,3,4$ which are $2,4,8,12$ respectively. These numbers hint on the fact that if there is a general polynomial formula for $\max(L)$ in terms of $n$ then it is a polynomial of degree $\ge 3$. However I sadly couldn't proceed anywhere further from this. The problem of minimizing $B$ seems way simpler than the original one, but I do not have any ideas on how to go about proving it as well. I would greatly appreciate any help or reference to this problem!