Loading
Loading
A small dinner has a single row of chairs and a guest list of distinct member numbers. The host wants to see every possible seating order before picking one.
Return every ordering of guests. Write each as the numbers comma-separated inside square brackets with no spaces, and list the orderings in lexicographic order as number sequences.
guests = [2, 1, 3]1 _ _seat the smallest guest first1 2 3, 1 3 2fill the remaining chairs smallest first2 _ _free chair one, seat the next guest there["[1,2,3]", "[1,3,2]", "[2,1,3]", "[2,3,1]", "[3,1,2]", "[3,2,1]"]Sign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
Six orders, listed from the smallest sequence to the largest.
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(n! · n) time · O(n) space
Input. Run your code to watch it work on this input, one line at a time.
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
Example 2
One guest can only sit one way.