Rearrange String by Alternating Ends
Reported by candidates from Hudson River Trading's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The constraint that matters here is s.length <= 100, so nothing in this Hudson River Trading problem needs cleverness to be fast. Reported in September 2026, the task is to rebuild a string by reading from alternating ends: index 0, then n-1, then 1, then n-2, and so on. It's a string and two-pointer problem, and it's mostly an off-by-one test. If you blank on the loop bounds, StealthCoder is the invisible safety net running during the live OA. Most candidates won't need it, but it's there if your mind goes empty.
The problem
Given a string s, return a new string formed by reading characters from alternating ends. Use the characters in this order: Take the first character. Take the last character. Take the second character. Take the second-to-last character. 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.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is two pointers. Set lo = 0 and hi = n-1. While lo <= hi, append s[lo] and increment lo. Then, if lo <= hi, append s[hi] and decrement hi. That second check is the whole pitfall. With odd length, the pointers meet on the middle character, and without the guard you'd append it twice. Example 1 shows it: abcde ends on c, used once. Also don't build the result with repeated string concatenation in a language where that's costly. Use a list or builder and join at the end. With n at most 100, even a quadratic approach passes, so brute force isn't the danger. Sloppy bounds are. Test length 1, length 2, and one odd and one even case before submitting. If the loop logic slips under pressure, StealthCoder can hand you a clean solution during the live OA.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Rearrange String by Alternating Ends cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Hudson River Trading's OA.
Hudson River Trading reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Rearrange String by Alternating Ends FAQ
How hard is the Hudson River Trading alternating ends problem really?+
Easy. It's a two-pointer string build with n up to 100. The only real risk is an off-by-one on odd-length strings, where the middle character gets duplicated or skipped. If you trace the three examples by hand, you'll catch it.
What's the trick to rearranging a string from alternating ends?+
Use two pointers, one at the start and one at the end. Take from the left, move it right, then take from the right, move it left. Check lo <= hi before each take so the middle character of an odd string is used only once.
Do I need an optimal solution given the constraints?+
No. Length is at most 100, so even a naive approach runs instantly. Still, write the O(n) two-pointer version with a list and join. It's just as short and it shows you know the clean approach.
Which edge cases should I test before submitting?+
Test length 1 ("x" returns "x"), length 2, an odd length like "abcde" giving "aebdc", and an even length like "abcdef" giving "afbecd". Those four cover every way the pointer logic can break.
Is this string pattern still asked in 2026 OAs?+
Yes. This one was reported for Hudson River Trading in September 2026. Two-pointer string and array manipulation shows up constantly as a warm-up question, so learn the pointer-and-guard pattern rather than memorizing this exact problem.