Top K Frequent Words
Updated
Problem statement
Given an array words and integer k, return the k most frequent distinct words.
Rank words by descending frequency. If two words have the same frequency, the lexicographically smaller word ranks first.
Function
topKFrequentWords(words: String[], k: int) → String[]Examples
Example 1
words = ["i","love","leetcode","i","love","coding"]k = 2return = ["i","love"]Both occur twice, and i is lexicographically smaller.
Example 2
words = ["the","day","is","sunny","the","the","the","sunny","is","is"]k = 4return = ["the","is","sunny","day"]Frequencies are 4, 3, 2, and 1.
Constraints
1 <= words.length <= 10^5.1 <= k <= number of distinct words.- Words are nonempty lowercase English strings.
More Bloomberg LP Onsite Interview questions
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Decode StringPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Minimum Replacements to Make Two Strings AnagramsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Currency Conversion RatePHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Running Stream AggregatesONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Top K Frequent ElementsCapgemini · ONSITE INTERVIEWCapgemini interview questions
- Top K Frequent Elements with Larger-Value Tie BreakOracle · ONSITE INTERVIEWOracle interview questions
- Top K Frequent ElementsInfosys · ONSITE INTERVIEWInfosys interview questions
- Top-K IP Addresses from File RecordsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Top K Keys from JSON RecordsCapital One · ONSITE INTERVIEWCapital One interview questions
- Streaming Top K Frequent ElementsAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Top K Frequent ElementsEricsson · ONSITE INTERVIEWEricsson interview questions
- Top-K KOLs by Total LikesTikTok · ONSITE INTERVIEWTikTok interview questions
- Worst-Performing Ads by CTR in a Campaign TreeUber · PHONE SCREENUber interview questions