This problem requires you to develop an algorithm that identifies the most frequently occurring elements in an input array, limited to a specified number k . For instance, given the array [1,1,2,2,3,3,3,4,4,4,4] with k=2 , the expected output is [4, 3] , as 4 and 3 are the two elements that appear most frequently. The frequency of an element is determined by how many times it appears in the array. Additionally, the ability to process large datasets is a crucial part of this challenge. The problem highlights the need for a solution that can efficiently manage "a case containing millions of elements," suggesting that an optimal approach should have a time complexity lower than O(n^2).