Leetcode problem topkfrequent elements


this is the leetcode question of which the solution that i wrote is attatched below :

here i have made a frequence array and based on the maximum element in the frequence array i have added then in the resulting vector k times. but i am getting the following error which i am not able to understand :

please tell me what is wrong in the code?