File: root - text - article - 2020 - 02 - top-k-frequent-words.txt
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 561 Views, 22632 Search Bots | 102 Words
| Browse | Archive
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 561 Views, 22632 Search Bots | 102 Words
| Browse | Archive
Hi, here's your problem today. This problem was recently asked by AirBNB:
Given a non-empty list of words, return the k most frequent words. The output should be sorted from highest to lowest frequency, and if two words have the same frequency, the word with lower alphabetical order comes first. Input will contain only lower-case letters.
Example:
Input: ["daily", "interview", "pro", "pro", "for", "daily", "pro", "problems"], k = 2
Output: ["pro", "daily"]
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Cateogry: Computing | 561 Views, 22632 Search Bots | 102 Words Given a non-empty list of words, return the k most frequent words. The output should be sorted from highest to lowest frequency, and if two words have the same frequency, the word with lower alphabetical order comes first. Input will contain only lower-case letters.
Example:
Input: ["daily", "interview", "pro", "pro", "for", "daily", "pro", "problems"], k = 2
Output: ["pro", "daily"]
class Solution(object):
def topKFrequent(self, words, k):
# Fill this in.
words = ["daily", "interview", "pro", "pro", "for", "daily", "pro", "problems"]
k = 2
print(Solution().topKFrequent(words, k))
# ['pro', 'daily']
Related Articles
- Daily Interview Puzzle: Intersection of Linked Lists
- Daily Interview Problem: Longest Substring With K Distinct Characters
- Algorithm Interview: Permutations of numbers
- Find Pythagorean Triplets
- Daily Interview Puzzle: Ways to Traverse a Grid
- Daily Interview Problem: Spiral Traversal of Grid
- Daily Interview Problem: Find the Number of Islands
- PHP Unit Tests on VPS Server
- How to Play WAV music under DOS?
- Algorithm Interview: No Adjacent Repeating Characters
©2006~2024 SteakOverCooked - 0.00715 Seconds(s) - 2787.545 KB/s - 27 Online Memory: 492.9 KB
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
How to Cook a Perfect Steak? | <meta name="robots" content="index, follow">
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
Comments (0)
Read & Write - Normal - Mini - Post - All Comments - Statistics
Be the first one to comment this page !