Sort by

recency

|

3633 Discussions

|

  • + 0 comments

    Ruby

    def migratoryBirds(arr)
      a = arr.tally
      a.max_by { |key, val| [val, -key] }.first
    end
    
  • + 0 comments

    can you help to integrate this algorithm script with my [portland flea for all ](https://antique-storesnear.me/portland-flea-for-all/)page. I want to use this on my site.

  • + 1 comment
      
            public int MaxSightings(List<int> arr)
            {
                Dictionary<int, int> sightings = new Dictionary<int, int>();
                int maxSightings = 0;
                foreach (int i in arr)
                {
                    if (sightings.ContainsKey(i))
                    {
                        sightings[i]++;
                    }
                    else
                    {
                        sightings[i] = 1;
                    }
    
                    maxSightings = Math.Max(maxSightings, sightings[i]);
                }
    
                int birdId = sightings.Where(kv => kv.Value == maxSightings).Min(kv => kv.Key);
    
                return birdId;
    
            }
    
  • + 0 comments
    class Pair{
            int val;
            int freq;
            Pair(int val,int freq){
                this.val=val;
                this.freq=freq;
            }
        }
    class Result {
    
        /*
         * Complete the 'migratoryBirds' function below.
         *
         * The function is expected to return an INTEGER.
         * The function accepts INTEGER_ARRAY arr as parameter.
         */
        
        public static int migratoryBirds(List<Integer> arr) {
        // Write your code here
            HashMap<Integer,Integer> mpp=new HashMap<>();
            for(int i=0;i<arr.size();i++){
                mpp.put(arr.get(i),mpp.getOrDefault(arr.get(i),0)+1);
            }
            int ans=Integer.MAX_VALUE;
            PriorityQueue<Pair> minheap=new PriorityQueue<>((a,b)-> a.freq==b.freq?a.val-b.val:b.freq-a.freq);
            for(Map.Entry<Integer,Integer> entry:mpp.entrySet()){
                minheap.add(new Pair(entry.getKey(),entry.getValue()));
            }
            return minheap.poll().val;
    
        }
    
    }
    
  • + 0 comments
    def migratoryBirds(arr):
        # Write your code here
        sights = {1:0,2:0,3:0,4:0,5:0}
        for bird_type in arr:
            sights[bird_type] += 1
        sorted_by_sights = sorted(sights.items(), key=lambda item: item[1], reverse=True)
        return sorted_by_sights[0][0]