
Given an array of integers, rearrange the elements in-place to form the next sequence in lexicographic order relative to the current arrangement; if no greater ordering exists, return the smallest (sorted ascending) arrangement. The solution should run in O(n) time and O(