Ctrl K
Python · Junior · Coding

Write a function top_words that takes a string of text and a number n, and returns the n most frequent words as a list of pairs: the word and how many times it occurred. Case doesn't matter, punctuation is discarded, and words with equal frequency are ordered alphabetically.

~15 min by voice

How to approach it

This checks whether you can carefully split text into words, count frequencies and sort by a compound key with a tie-breaker. Just as important is whether you clarify the problem before coding and think about edge cases.

Have you seen this question in a real interview?
Answers0
Avg. score—
Strong—
Practiced0
Topics
Similar questionsДан список отрезков, каждый задан началом и концом. Нужно объединить все пересекающиеся отрезки. Например, из [1, 3], [2, 6], [8, 10], [15, 18] получается [1, 6], [8, 10], [15, 18]. Mid-levelДан неотсортированный массив различных целых чисел. Сверните его в строку диапазонов через запятую. Например, для массива [1, 4, 5, 2, 3, 9, 8, 11, 0] ответ — строка «0-5,8-9,11». Mid-level

Answer by voice

The interviewer will ask this question and listen. Think out loud and ask for a hint if you need one. When you're done, pause or tap “That's my answer”. In about a minute, your score and the points you covered show up here.

Sign in to answer

Best with headphones · ~15 min