← 返回 netflix 的题目列表Design a word counter for streaming text
类型:online_judge
Implement a WordCounter class to count word frequencies from streaming text.
You will receive multiple chunks of text over time. Split each chunk into words and accumulate counts. Provide a query API to return the total count for a given word.
Implement:
add(text: str) -> None
count(word: str) -> int (return 0 if absent)
Constraints / defaults:
Words are separated by whitespace (spaces/newlines/tabs).
Case-sensitive.
Input size: each chunk up to 1e5 characters; total up to 1e6.
Provide 5 test cases covering casing, duplicates, empty input, multiple spaces, and newlines.
Example
Input
add: "hello world hello"\ncount: "hello"
Output
2