Next Permutation

A sequence of $N$ distinct integers is called a permutation if all the integers are between $1$ and $N$ (inclusive).


This is a companion discussion topic for the original entry at https://toph.co/p/next-permutation