Counting a property of every sub-sets

Consider a array $ a$ of length $ n$ and $ a_i<n$ and a array of length $ n$ ,$ b=[0,0….(n$ $ times)]$ .Consider every sub-set of array $ a$ and denote it by $ s$ i need to find a number $ k$ with the largest number of occurrences or the most frequent one, If there are several options, choose the smallest one and then increase $ b[k]$ by one .I need to final $ b$ after considering all sub sets.

My idea is that ,I make a array $ val$ of length $ n$ where $ val[i]$ is number of times $ i$ occurred in array $ a$ .Consider that i am trying to find value for $ b[k]$ then i will create a array $ temp$ of length where $ temp[i]=min(val[k],val[i])$ .Then consider the value of $ val[k]$ to be $ m$ then in a subset element $ k$ can occur from $ 0$ to $ m$ times and using this i will find answer for all of its occurrences from $ 0$ to $ m$ which is a simple number of sub sets problem and finally i will have my answer.

But my algorithms complexity is bad as it quadratic or worse.Could anyone help me.