Sort by

recency

|

1942 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

    Python3 solution

    s = sorted(set(arr))
    k = []
    
    for x in range(0,len(s)):
        k.append(arr.count(s[x]))
    
    return(len(arr)-max(k))
    
  • + 0 comments
        public static int equalizeArray(List<Integer> arr) {
        // Write your code here
            Set<Integer> liste = new HashSet<>(arr);
            int occ;
            int most=0;
            for(int n : liste){
                occ=0;
                for(int m : arr){
                    if(n==m){
                        occ++;
                    }
                }
                if(occ>most)
                    most=occ;
            }
            return arr.size()-most;
        }
    
  • + 0 comments
    sub equalizeArray {
        my $array = shift;
        my %freq;
        $freq{$_}++ for @$array;
        my @freq = sort { $freq{$b} <=> $freq{$a} } keys %freq;
        return @$array - $freq{$freq[0]};
    }
    
  • + 0 comments
    C#
    
        public static int equalizeArray(List<int> arr)
    {
        int element = 
            arr
            .GroupBy(x => x)
            .OrderByDescending(x => x.Count())
            .FirstOrDefault()
            .Key;
    
        int result = arr.Count(x => x != element);
    
        return result;
    }