PracHub
QuestionsCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Capital One

Reorder a String by Alternating Its Left and Right Ends

Last updated: Jul 22, 2026

Quick Overview

Reorder a string by alternately taking the next character from its left and right ends until every character appears exactly once. This string-processing problem tests index boundaries, odd and even lengths, empty input, exact preservation of spaces and symbols, and linear construction at large scale.

  • medium
  • Capital One
  • Coding & Algorithms
  • Software Engineer

Reorder a String by Alternating Its Left and Right Ends

Company: Capital One

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Take-home Project

# Reorder a String by Alternating Its Left and Right Ends Given a string `text`, construct a new string by taking characters in this order: 1. first character, 2. last character, 3. second character, 4. second-to-last character, 5. and so on until every character has been used exactly once. Return the reordered string. ## Function Signature ```python def alternate_ends(text: str) -> str: ... ``` ## Constraints - `0 <= len(text) <= 1_000_000` - `text` contains printable ASCII characters, so every supported language agrees on character boundaries. - Preserve each character exactly; do not trim or normalize the input. ## Examples ```text Input: text = "abcde" Output: "aebdc" ``` ```text Input: text = "abcd" Output: "adbc" ``` ```text Input: text = "" Output: "" ```

Quick Answer: Reorder a string by alternately taking the next character from its left and right ends until every character appears exactly once. This string-processing problem tests index boundaries, odd and even lengths, empty input, exact preservation of spaces and symbols, and linear construction at large scale.

Related Interview Questions

  • Arrange Match Results in Repeating Win-Draw-Loss Order - Capital One (medium)
  • Sort Every Concentric Matrix Border Clockwise - Capital One (medium)
  • Count Pairs of Cyclically Equivalent Integers - Capital One (medium)
  • Sort Matrix Diagonals By Their Values - Capital One (medium)
|Home/Coding & Algorithms/Capital One

Reorder a String by Alternating Its Left and Right Ends

Capital One logo
Capital One
Jul 21, 2026, 12:00 AM
mediumSoftware EngineerTake-home ProjectCoding & Algorithms
0
0

Reorder a String by Alternating Its Left and Right Ends

Given a string text, construct a new string by taking characters in this order:

  1. first character,
  2. last character,
  3. second character,
  4. second-to-last character,
  5. and so on until every character has been used exactly once.

Return the reordered string.

Function Signature

def alternate_ends(text: str) -> str:
    ...

Constraints

  • 0 <= len(text) <= 1_000_000
  • text contains printable ASCII characters, so every supported language agrees on character boundaries.
  • Preserve each character exactly; do not trim or normalize the input.

Examples

Input: text = "abcde"
Output: "aebdc"
Input: text = "abcd"
Output: "adbc"
Input: text = ""
Output: ""

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Capital One•More Software Engineer•Capital One Software Engineer•Capital One Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.