FastPrepRearrange a String Outside In

Rearrange a String Outside In

ZipRecruiter logoZipRecruiter● EasyNEW GRADOA
Learn

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) → String

Examples

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

More ZipRecruiter problems

See ZipRecruiter hiring insights
public String outsideIn(String text) {
    // Write your code here.
}
text"abcdef"
expected"afbecd"
Checking account…