A layout tool lets designers flip through every arrangement of the widgets on a page, in sorted (dictionary) order. An arrangement is an array of widget numbers in order.
Write nextArrangement(order) that returns a new array: the arrangement that comes right after order in sorted order. If order is already the last arrangement (sorted descending), wrap around and return the first one (sorted ascending).
Numbers may repeat. Arrangements that look the same count once.
Input: order = [1,2,3] Output: [1,3,2]
In sorted order, [1, 2, 3] is followed by [1, 3, 2].
Input: order = [3,2,1] Output: [1,2,3]
[3, 2, 1] is the last arrangement, so wrap around to the first.
1 <= order.length <= 1000 <= order[i] <= 100Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #299 Next Layout Arrangement. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.