Computer Science Undergraduate · Author has 152 answers and 813.9K answer views · Updated 10y ·
Rough Algorithm :
- Take the permutation 1 2 3 .... n. For example if n=5 take permutation 1 2 3 4 5. Call It original sequence.
- Mark all the continuous occurrences of D in the given signature.
- Then for each continuous sequence of D, going from left to right reverse the strip corresponding to that in original sequence.Every time make the new sequence as original sequence.
Example :
- Take the above case. Signature = DDIIDI.
- Take original permutation as 1 2 3 4 5 6 7.
- Then for first continuous sequence DD reverse the strip 1 2 3 to 3 2 1 hence sequence becomes 3 2 1 4 5 6 7.
- Then for second sequence D reverse strip 5 6 to 6 5 hence sequence becomes 3 2 1 4 6 5 7.
- There is no continuous D left we are done and reached the answer.
Source : Lexicographically Smallest permutation given a signature
1.5K views ·
View upvotes
· 1 of 3 answers
Something went wrong. Wait a moment and try again.