PracticeStrings

Even-Move Replay Marker

BeginnerStringstraversalaccumulationindex arithmetic Time not estimated Not started

Context

In the arcade game Neon Sprint, a replay is stored as a sequence of lowercase letters and spaces describing the moves a player made. The scoring engine keeps markers from moves at alternating positions to create a compact replay tag. You must retain the characters at even zero-based positions, leaving the original order unchanged.

Problem

Write a function that receives a replay string. Positions are counted from zero, so the first character is at position 0. Build and return a new string containing exactly the characters found at even positions: 0, 2, 4, and so on. Keep every retained character in its original order, including spaces. Do not modify the input string. If the replay is empty, return an empty string.

Examples

Example 1
Input: replay = "hello"
Output: "hlo"
Explanation: For replay "hello", the executed output is "hlo".
Example 2
Input: replay = "move now"
Output: "mv o"
Explanation: For replay "move now", the executed output is "mv o", including the space as a retained character.
Example 3
Input: replay = "cat nap"
Output: "ctnp"
Explanation: For replay "cat nap", the executed output is "ctnp".

Constraints

  • 0 <= len(replay) <= 120
  • replay contains only lowercase letters and spaces.
  • Types: replay is str; result is str

Function signature

def keep_even_move_markers(replay: str) -> str
replay str
The replay text recorded by the player.
returns str
A string containing the characters from even zero-based positions of replay, in their original order.

Adapted from MBPP problem task_437 (CC BY 4.0). Rewritten, extended and verified by Iksha.

Approved · cb045-abs_891_v114 execution-verified tests
Code
Saved
Checking environment…Python SandboxLn 1, Col 1