FastPrepRearrange String by Alternating Ends
Problems/Rearrange String by Alternating Ends

Rearrange String by Alternating Ends

Hudson River Trading logoHudson River Trading● EasyFULLTIMENEW GRADINTERNOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: The source omits a language-specific signature. The judged core task and both visible examples match the source at about 99%.

Given a string s, return a new string formed by reading characters from alternating ends.

Use the characters in this order:

  1. Take the first character.
  2. Take the last character.
  3. Take the second character.
  4. Take the second-to-last character.
  5. Continue moving inward until every character has been used exactly once.

Equivalently, for a string of length n, visit indices 0, n - 1, 1, n - 2, and so on.

Function

solution(s: String) → String

Examples

Example 1

s = "abcde"return = "aebdc"

The characters are taken from indices 0, 4, 1, 3, and 2, producing aebdc.

Example 2

s = "abcdef"return = "afbecd"

The characters are taken from indices 0, 5, 1, 4, 2, and 3, producing afbecd.

Example 3

s = "x"return = "x"

A one-character string has the same character at the only position, so the result is x.

Constraints

  • 1 <= s.length <= 100
  • s contains only lowercase English letters.

More Hudson River Trading problems

  • Format a Signed Integer with CommasPHONE SCREEN · Seen Nov 2026
  • Order and Batch Open-Close LifecyclePHONE SCREEN · Seen Nov 2026
  • Count Palindrome Addition ChoicesOA · Seen Nov 2026
All Hudson River Trading interview questionsSee Hudson River Trading hiring insights
Saved
class Solution {
    public String solution(String s) {
      // Write your code here.
    }
}
Checking account…