PracticeStrings

Mark Vowels on a Shipment Label

EasyStringstraversalstate trackingfiltering Time not estimated Not started

Context

A warehouse prints handling labels for outgoing shipments. To make selected labels easier to inspect, the printer may change up to a given number of lowercase vowels into the marker letter x. Spaces and consonants must remain unchanged, and vowels are considered from left to right.

Problem

Given a shipment label and a replacement quota, process the label from left to right. For each lowercase vowel (a, e, i, o, or u), replace it with the lowercase letter x while the quota still allows replacements. Once the quota is used, leave every later character unchanged. Return the resulting label.

Spaces and consonants are never replaced. The returned label must have the same length and preserve the order of every character. If the quota is zero, return the label unchanged; if the label is empty, return an empty string.

Examples

Example 1
Input: label = "alpha team"quota = 2
Output: "xlphx team"
Explanation: For label "alpha team" with quota 2, the executed result is "xlphx team".
Example 2
Input: label = "blue rocket"quota = 8
Output: "blxx rxckxt"
Explanation: For label "blue rocket" with quota 8, the executed result is "blxx rxckxt"; the trace records four replacements.
Example 3
Input: label = "quiet zone"quota = 0
Output: "quiet zone"
Explanation: For label "quiet zone" with quota 0, the executed result is "quiet zone" with zero replacements.

Constraints

  • 0 <= len(label) <= 100000
  • 0 <= quota <= len(label)
  • label contains lowercase letters and spaces
  • Types: label is str, quota is int; result is str

Function signature

def mark_shipment_label(label: str, quota: int) -> str
label str
The shipment label, containing lowercase letters and spaces.
quota int
The maximum number of vowels that may be replaced.
returns str
The label after replacing up to quota vowels from left to right with x.

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

Notes

  • Only lowercase vowels are eligible for replacement.
  • The replacement limit is never exceeded.
Approved · cb055-abs_674_v214 execution-verified tests
Code
Saved
Checking environment…Python SandboxLn 1, Col 1