To the Top
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 | 260 Views, 17710 Search Bots | 102 Words

Subscribe to Feed Burner | 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"]


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']
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Cateogry: Computing | 260 Views, 17710 Search Bots | 102 Words Subscribe to Feed Burner

Related Articles

  1. Daily Interview Question: Longest Sequence with Two Unique Numbers
  2. [Daily Problem] Add two numbers as a linked list
  3. Floor and Ceiling of a Binary Search Tree
  4. Daily Interview Problem: Min Range Needed to Sort
  5. Daily Interview Problem: Merge Overlapping Intervals
  6. Daily Interview Problem: First Missing Positive Integer
  7. [Daily Problem] Validate Balanced Parentheses
  8. Find Missing Numbers in an Array
  9. Daily Interview Problem: Find the k-th Largest Element in a List
  10. Skip the readings, focus on problems. And use all the hints!

Comments (0)

Your Email (Domain Part Not Exposed):

Your Comments:

Privately By Mail Colors More Smileys S x y @

Verification (Click Image 2 Refresh):

    Be the first one to comment this page !


Page Edited: October 30 2020 14:21:09 | RSS Subscription
How to Cook a Perfect Steak? | <meta name="robots" content="noindex, follow" />