PracticeStrings
Fill the Combo Meter
Context
A game displays a level-up combo label as a string. Blank spaces mark unfinished slots, and the score screen provides a character to fill them. Transform the label so every blank slot shows that character while every existing lowercase letter stays unchanged.
Problem
Write a function that updates a level-up combo label. Replace every space in the input label with the supplied lowercase character. Leave every lowercase letter exactly where it is, preserving the label's order and length. If the label has no spaces, return it unchanged. A label may be empty, and spaces at either end or next to one another must all be processed.
Examples
Example 1
Input:
fill_symbol = "x"label = "combo level"Output:
"comboxlevel"Explanation: For label "combo level" and fill_symbol "x", the executed result is "comboxlevel". The traced output contains the original letters and x at the space position.
Example 2
Input:
fill_symbol = "a"label = " boost chain "Output:
"aaboostaachaina"Explanation: For label " boost chain " and fill_symbol "a", the executed result is "aaboostaachaina". The traced output contains a for the leading, repeated, and trailing spaces.
Example 3
Input:
fill_symbol = "z"label = ""Output:
""Explanation: For the empty label and fill_symbol "z", the executed result is the empty string. The traced output list is empty and position is 0.
Constraints
0 <= len(label) <= 10001 <= len(fill_symbol) <= 1label contains lowercase letters and spacesfill_symbol contains only lowercase letters- Types:
labelis str,fill_symbolis str; result is str
Function signature
def fill_combo_slots(label: str, fill_symbol: str) -> str
labelstr- The combo label, containing lowercase letters and spaces.
fill_symbolstr- The single lowercase character used for every blank slot.
- returns str
- The same-length combo label with every space replaced by fill_symbol and every other character unchanged.
Adapted from MBPP problem task_230 (CC BY 4.0). Rewritten, extended and verified by Iksha.
Notes
- The input may be empty.
- Only the space character is replaced; no other whitespace or character rule is involved.
- The transformation preserves order and length.
Code
Saved