Skip to content

Add an O(n) solution for Top K Frequent Elements problem #2586

Description

@IbarakiRino

Top K Frequent Elements problem
Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order.
Algorithm Introduction
The bfprt algorithm is used to find the smallest k element in the array. The bfprt algorithm can find the answer in O(n) time.

bfprt algo

Blum M, Floyd R W, Pratt V R, et al. Time bounds for selection[J]. J. Comput. Syst. Sci., 1973, 7(4): 448-461.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions