Hi,
Solution provided to the second problem is not correct, as per question
Input: [5, 12, 11, 3, 11], K = 2
answer should be the following
Output: [11, 5] or [11, 12] or [11, 3]
But when you run the sample following is seen:
Here are the K frequent numbers: 12 11
Here are the K frequent numbers: 12 11
This is happening so because only 2 elements are kept in heap and remaining elements are getting removed. One way to avoid is to see if frequency is same, if it so then push back. But again pairing has to be created from the final list. So the code is incomplete.