This question evaluates understanding of permutations and lexicographic ordering, in-place array manipulation, handling of duplicate elements, and algorithmic complexity with constraints on O(n) time and O(1) extra space.

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(