The Top Words
A medium Python interview practice problem on DataDriven. Write and execute real python code with instant grading.
- Domain
- Python
- Difficulty
- medium
- Seniority
- L4
Problem
Given a text string and integer k, split on whitespace, count occurrences, and return the k words with the highest counts. Sort by count descending, tie-break alphabetically ascending. If fewer than k distinct words exist, return all of them.
Summary
In every document, some words dominate the conversation.
Practice This Problem
Solve this Python problem with real code execution. DataDriven runs your Python code in a real environment and grades it automatically.