PracticeStrings

Parity Combo Collector

EasyStringstraversalfilteringindex arithmetic Time not estimated Not started

Context

A player enters a lowercase move string during a gaming challenge. The level's combo rule selects either even-positioned or odd-positioned moves, using zero-based positions. Build the move sequence that survives this rule so the score engine can evaluate that combo.

Problem

Write a function that receives a move string and a parity choice. Positions are zero-based: position 0 is even, position 1 is odd, and so on. Keep every character whose position has the chosen parity, preserving the order in which moves appeared. Omit all other characters. If the move string is empty, return an empty string.

Examples

Example 1
Input: moves = "wasd"parity = 0
Output: "ws"
Explanation: For moves "wasd" and parity 0, the executed result is "ws".
Example 2
Input: moves = "jump"parity = 1
Output: "up"
Explanation: For moves "jump" and parity 1, the executed result is "up".
Example 3
Input: moves = ""parity = 0
Output: ""
Explanation: For an empty move string, the executed result is an empty string.

Constraints

  • 0 <= len(moves) <= 200
  • moves: alphabet lowercase
  • 0 <= parity <= 1
  • moves contains only lowercase letters.
  • Types: moves is str, parity is int; result is str

Function signature

def collect_parity_moves(moves: str, parity: int) -> str
moves str
The sequence of lowercase move characters entered by the player.
parity int
The position parity to keep: 0 for even positions or 1 for odd positions.
returns str
The move string containing only characters at positions whose zero-based parity equals parity, in original order.

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

Notes

  • Use zero-based positions, so the first character is at position 0.
  • An empty moves string is valid and produces an empty result.
Approved · cc014-abs_656_v314 execution-verified tests
Code
Saved
Checking environment…Python SandboxLn 1, Col 1