Reported September 2026
Capital Onetwo pointers

Alternate String Ends

Reported by candidates from Capital One's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Capital One OA. Under 2s to a working solution.
Founder's read

The mistake that sinks a first attempt on this one is double-counting the middle character. Capital One reported this OA in September 2026, and it's a clean string problem: build a new string by reading from alternating ends, indices 0, n-1, 1, n-2, and so on. It looks trivial, and it mostly is. The failures come from odd-length strings and off-by-one stops. If you blank on the loop condition, StealthCoder is the safety net running invisibly during the live OA. But you can own this in ten minutes of thought.

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
alternateStringEnds(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.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is two pointers. Set left = 0 and right = n-1. While left <= right, append s[left], then if left != right, append s[right]. Move left up and right down. That left != right check is the whole problem. Skip it on an odd-length string like "abcde" and you append 'c' twice, returning "aebdcc" instead of "aebdc". The one-character case "x" hits the same bug. Use left < right in the loop and handle the leftover middle after, or keep the guard inside. Either works. Build with a list or StringBuilder and join at the end, because repeated string concatenation can go quadratic in some languages. Time is O(n), space is O(n). Test the three given examples by hand before submitting. If the live OA freezes you on pointer bounds, StealthCoder can hand you the loop, but the logic here is short enough to write from memory.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Alternate String 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. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Capital One's OA.

Capital One reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Alternate String Ends FAQ

How hard is Alternate String Ends really?+

Easy. It's a two-pointer string build with one edge case. If you can write a while loop with left and right indices, you can solve it. Most of the difficulty is in not duplicating the middle character on odd-length input.

What's the trick to getting it right the first time?+

Guard the second append. After taking s[left], only take s[right] if left != right. That single condition handles odd lengths and the one-character string. Without it, the middle character shows up twice in your output.

Is there a way to solve it without two pointers?+

Yes. Loop i from 0 to n-1 and pick index i/2 when i is even, or n-1-i/2 when i is odd. Same O(n) result. Two pointers is easier to reason about and less likely to cause an off-by-one under pressure.

What edge cases should I test before submitting?+

Test a one-character string, an even-length string like "abcdef", and an odd-length string like "abcde". Also try the empty string if constraints allow it. Those cover every branch of the loop and the middle-character case.

How do I prepare for this in 48 hours?+

Don't grind. Write this solution once from scratch, then do two or three other two-pointer string problems like reversing or palindrome checks. Know your language's efficient string builder. That's enough for a problem at this level on the Capital One OA.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Capital One.

OA at Capital One?
Invisible during screen share
Get it