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 | 315 Views, 19240 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 | 315 Views, 19240 Search Bots | 102 Words Subscribe to Feed Burner

Related Articles

  1. Daily Interview Problem: Sort Colors
  2. Daily Interview Problem: Minimum Removals for Valid Parenthesis
  3. Linode Support Ticket 10029540 - Other - Important Notice Regarding Ubuntu 17.10 Image
  4. Daily Interview Problem: Largest Product of 3 Elements I
  5. Algorithm Interview: Convert Roman Numerals to Decimal
  6. A trick for getting good at coding interviews FASTER
  7. Print a tree level-by-level, with line-breaks
  8. Daily Interview Problem: Circle of Chained Words
  9. Daily Interview Puzzle: Intersection of Linked Lists
  10. Daily Interview Question: Longest Sequence with Two Unique Numbers

Comments (0)

    Be the first one to comment this page !


Page Edited: May 11 2024 14:36:49 | RSS Subscription
How to Cook a Perfect Steak? | <meta name="robots" content="noindex, follow" />