Simple Fun #159: Middle Permutation
Last updated
Was this helpful?
Last updated
Was this helpful?
You are given a string s
. Every letter in s
appears once.
Consider all strings formed by rearranging the letters in s
. After ordering these strings in dictionary order, return the middle term. (If the sequence has a even length n
, define its middle term to be the (n/2)
th term.)
For s = "abc"
, the result should be "bac"
.
[input]
string s
unique letters (2 <= length <= 26
)
[output]
a string
middle permutation.