We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Migratory Birds
Migratory Birds
Sort by
recency
|
3522 Discussions
|
Please Login in order to post a comment
SOLUTION USING PYTHON
def migratoryBirds(arr): maxOfarr = max(arr) temp = [0]*(maxOfarr+1) for i in arr: temp[i] += 1 maxOfTemp = max(temp)
Python 3 def migratoryBirds(arr): ele=list(set(arr)) ele.sort() res=[] for i in ele: res.append(arr.count(i))
max_count=max(res) return ele[res.index(max_count)]
java
public static int migratoryBirds(List arr) { // Write your code here int f=0; int b=0; HashSet s=new HashSet<>(arr); Iterator it=s.iterator(); while(it.hasNext()) { int val=(int)it.next(); int a=(int)Collections.frequency(arr,val); if(a>f) { f=a; b=val; } else if(a==f) { if(val
python3
birdsid_count = {} for i in arr: if i in birdsid_count: birdsid_count[i] += 1 else: birdsid_count[i] = 1 max_ids = max(birdsid_count.values()) max_items = [key for key, value in birdsid_count.items() if value == max_ids] results = min(max_items) return results