Given an array of integers, rearrange it into the lexicographically next greater permutation. If no such permutation exists (array is in descending order), rearrange to the smallest permutation (ascending order).
For [1,2,3], the next permutation is [1,3,2]. For [3,2,1], wrap around to [1,2,3]. This tests your understanding of permutation ordering.