Word slips: Threshold file
Inputs
line is text. A character is one letter, digit, space, or punctuation mark.
Your tasks
- Create a list
wordLengths. Readlinefrom left to right. Here, a word is a group of characters with no spaces inside it. Record the length of each word. Ignore extra spaces before, after, or between words. For "a cat",wordLengthsis [1, 3]. - Count the numbers in
wordLengthsthat are at leastk(greater than or equal tok). Store the count inatLeastK. - Complete
wordSlipsThresholdFileso it returnsatLeastK. Return it, do not print it.
Example
If line is "un hvd" and k is 4, then wordLengths is [2, 3] and wordSlipsThresholdFile returns 0.
Rules
- If
wordLengthsis empty, the count is 0. k(a whole number from 1 to 8) is the threshold in task 2: compare each number with it.
Test data
TEST DATA 1: line is "eeenj sdddc" and k is 4.
TEST DATA 2: line is "EE eEE" and k is 1.
Examples
Input: line = "eeenj sdddc" k = 4 Output: 2
wordLengths is [5, 5]. Here k is 4. The numbers at least 4 are [5, 5]. There are 2, so return 2.
Input: line = "EE eEE" k = 1 Output: 2
wordLengths is [2, 3]. Here k is 1. The numbers at least 1 are [2, 3]. There are 2, so return 2.
Input: line = "" k = 8 Output: 0
wordLengths is []. Here k is 8. The numbers at least 8 are []. There are 0, so return 0.
Input limits
- 0 <= input size <= 64.
- k is a whole number from 1 to 8. Answers fit in a signed 32-bit integer: -2,147,483,648 through 2,147,483,647.
- The text uses ASCII characters (a basic character set). Only an ordinary space separates words.
Efficiency goal
Big-O describes how the work or memory needed grows as the input gets larger.
Efficiency goal: time O(n); extra memory, including the helper list, O(n). n is the input length. These labels describe how work and memory grow with the input.
Practice focus
Build wordLengths first, then return exactly what the tasks ask for. Follow the order, keep repeated values when the rule says so, and check the empty case.