
Finding Most Frequent Elements in an Array
Problem Statement We have to implement a topKFrequent function that takes an integer array and a value k as input and returns the k most frequent elements in the input array. For example, topKFrequent({1, 1, 2, 2, 3, 5, 2}, 2) will return the top 2 most frequent elements in the array i.e. {2, 1}. If multiple elements have the same frequency, then any of them could be returned in the solution as long as its length is k....