Question: Given an integer array nums and an integer k , return the k most frequent elements and how many times the elements have appeared. Example

Given an integer array nums and an integer k, return the k most frequent elements and how many times the elements have appeared.
Example :
Input: nums =[1,1,1,2,2,3], k =2 Output:
Element Count
13
22
Requirements :
The program must be implemented using C++11. The program will be compiled using g++for evaluation.
The elements must be read from the given file "hw4_10000Numbers_1to200.txt" which contains 10000 integers between 1 to 200.
k must be input from the command line.
The program needs to be able to handle the improper k values. (k is at least one. k cannot be
greater than the number of unique elements in the array.)
Your algorithms time complexity must be better than O(n log n), where n is the arrays size.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!