PracticeStrings

Level Log Token Hunt

EasyStringstraversalstate trackingfiltering Time not estimated Not started

Context

After a gaming session, a level log records lowercase words separated by spaces. Some words describe achievements, while others are too short to be useful. Build a helper for the score system that keeps every log word whose length reaches the chosen minimum, including repeated words and keeping their original order.

Problem

Given a log string and a minimum word length, return every complete word in the log whose length is at least the threshold. A word is a maximal consecutive sequence of lowercase letters, and spaces separate words. Preserve each qualifying occurrence in encounter order; do not merge repeated words or remove duplicates. If the log is empty or no word qualifies, return an empty string array.

Examples

Example 1
Input: log_text = "dark corridor opened slowly"minimum_length = 5
Output: ["corridor", "opened", "slowly"]
Explanation: For "dark corridor opened slowly" with minimum length 5, the executed result is ["corridor", "opened", "slowly"]. The final result count is 3.
Example 2
Input: log_text = "echo echo lantern"minimum_length = 4
Output: ["echo", "echo", "lantern"]
Explanation: For "echo echo lantern" with minimum length 4, the executed result is ["echo", "echo", "lantern"], so both repeated occurrences remain in the result.
Example 3
Input: log_text = "red dim fog"minimum_length = 4
Output: []
Explanation: For "red dim fog" with minimum length 4, the executed result is [] because the final result count is 0.

Constraints

  • 0 <= len(log_text) <= 1000
  • 1 <= minimum_length <= 1000
  • log_text contains only lowercase letters and spaces.
  • Types: log_text is str, minimum_length is int; result is str[]

Function signature

def qualifying_level_words(log_text: str, minimum_length: int) -> list[str]
log_text str
The level log containing lowercase words separated by spaces.
minimum_length int
The smallest length a word may have to be included.
returns list[str]
All qualifying words, one entry per occurrence, in the same order as they appear in the log.

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

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