Rearrange a String Outside In
Problem statement
You are given a string text. Build a new string by taking the first remaining character, then the last remaining character, and continuing inward.
If the length is odd, append the middle character last.
Function
outsideIn(text: String) → StringExamples
Example 1
text = "abcdef"return = "afbecd"The pairs are a/f, b/e, and c/d.
Example 2
text = "abcde"return = "aebdc"The pairs are a/e and b/d, followed by the middle c.
Constraints
0 <= text.length <= 100000