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.
# Step 1: Build frequency hash manually
for i in arr
if freq.has_key?(i)
freq[i] += 1
else
freq[i] = 1
end
end
# Step 2: Find the highest frequency
max_freq = 0
for key in freq.keys
if freq[key] > max_freq
max_freq = freq[key]
end
end
# Step 3: Among all bird types with max frequency, find the smallest ID
min_id = nil
for key in freq.keys
if freq[key] == max_freq
if min_id.nil? || key < min_id
min_id = key
end
end
end
return min_id
end
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Migratory Birds
You are viewing a single comment's thread. Return to all comments →
def migratoryBirds(arr) freq = {}
end