Facebook Interview question | Solutions Engineer | Phone Screen
Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2020-03-27Added By Anonymous
Source: Link
Company: Meta (Facebook)
Role: Solutions Engineer
Interview Stage: Phone Screen
Location: unknown
Year: unknown
Original Post Content:
Given an unsorted array return the k most frequent elements in O(N) time.
For example, [1,2,1,1,2,3,4,2,1,1,1,3] and k=2 return [1,2]
I gave a O(N * logK) solution using heap and a hashmap, does anyone know the O(N) solution to this?