The first step would be to convert your statements into a mathematical statement that we can manipulate.
Let the man paint posts $a_1, a_2, a_3, \ldots, a_n$ in that order. Then, the number of steps that he would take between posts $a_i$ and $a_{i+1}$ is $|a_i - a_{i+1}|$. Hence, the total number of steps is
$$ \sum_{i=1}^{n-1} | a_i - a_{i+1} | $$
Now, when we expand each individual absolute value term, we will either get $a_i - a_{i+1}$ or $a_{i+1} - a_i$.
Claim: $$ |a_n-a_1| + \sum_{i=1}^{n-1} | a_i - a_{i+1} | = \sum k_i a_i$$
where $k_i \in \{ -2, 0, 2\}$ and $\sum k_i = 0 $.
The proof is left to you, and should be obvious.
Now, if we wish to maximize this sum (i.e. most inefficient), it is clear that this is maximal when $k_i = 2$ for large values of $a_i$ and $k_i = -2$ for small values of $a_i$. In particular,
$$ k_i = \begin{cases} -2 & a_i\leq \frac {n+1}{2} \\ 0 & a_i = \frac {n+1} {2} \\ 2 & a_i > \frac {n+1}{2} \end{cases}.$$
I leave it to you to verify that with these coefficients, you would get a sum of $2\lfloor \frac {n}{2} \rfloor \lceil \frac {n}{2} \rceil$.
Hence,
$$ \sum_{i=1}^{n-1} | a_i - a_{i+1} | \leq 2n - | a_{n} - a_{1} | \leq 2\lfloor \frac {n}{2} \rfloor \lceil \frac {n}{2} \rceil-1 $$
It remains to verify that this can actually be achieved. If you understand what has been happening above, you should be able to quickly construct an example walk with this length.
Hint: What must the starting and ending posts be? How does he walk?
From the construction of the inequality, we know that we want to alternate back and forth between posts of value $\leq \frac {n+1}{2}$ and posts of value $\geq \frac {n+1}{2}$. We also want $|a_n - a_1| = 1$. We provide a construction as follows:
For even $n=2k$, paint posts
$$k+1, 1, 2k, 2, 2k-1, \ldots, k-2, k+3, k-1, k+2, k.$$
For odd $n=2k+1$, pain posts
$$k+1, 1, 2k+1, 2, 2k, \ldots, k-2, k+4, k-1, k+3, k, k+2.$$
Note that, with the exception of the starting and ending posts, we can permute the positions of the posts, as long as their new position has the same parity.