Suppose we have the set $\{1,...,n\}$ and we are given a permutation of its' elements, say for $n=4$ we have $3214$. Then we are given an index $i$ (say indexes go from $1$ to $n$) and we are asked to find the next smallest permutation that is greater than the current permutation, in lexicographical order, where the number at position $i$ in the given permutation is not in its' place. For example, for index $2$ in our given permutation, the next greater permutation where the $2$ is not at position $2$ is $3412$.
I have thought about this and it is easy to just start lexicographically pass on all permutations that are greater than the current one until we reach one where the number at index $i$ is changed. There is an algorithm for that, but that solution is trivial. Is there a way to find it without having to pass over all permutations in between?