Sort by

recency

|

1935 Discussions

|

  • + 0 comments

    Here is my O(N) c++ solution, you can watch the explanation here : https://youtu.be/8p9yuqSv4ek

    int equalizeArray(vector<int> arr) {
        map<int, int>mp;
        int mx = 0;
        for(int el: arr) {
            mp[el]++;
            if(mp[el]>mx) mx = mp[el];
        }
        return arr.size() - mx;
    }
    
  • + 0 comments

    Python

    from collections import Counter
    
    def equalizeArray(arr):
       return len(arr) - max(Counter(arr).values(), default=0)
    
  • + 0 comments

    Solutions in Python using collectinos lib:

    def equalizeArray(arr):
        ctr = Counter(arr)
        dct = dict(ctr.items())
        max_val = max(dct.values())
        
        return len(arr) - max_val
    
  • + 0 comments
    l=len(arr)
        d_arr={}
        for i in arr:
            if i in d_arr:
                d_arr[i]=d_arr[i]+1 
            else:
                d_arr[i]=1 
        ma=0
        ans=list()
        for i in arr:
            if d_arr[i]>ma:
                ma=d_arr[i] 
        return l-ma
    

    `

  • + 0 comments

    Here is my one line Python solution utilizing a Counter object!

    def equalizeArray(arr):
        return sum(Counter(arr).values()) - max(Counter(arr).values())