You are viewing a single comment's thread. Return to all comments →
Rust O(n) solution
fn migratoryBirds(arr: &[i32]) -> i32 { let mut counter = HashMap::new(); for a in arr { let mut count = counter.entry(a).or_insert(0); *count += 1; } let mut max_birds = 0; let mut ans = -1; for (key, value) in counter { if (value > max_birds) | ((value == max_birds) & (*key < ans)) { max_birds = value; ans = *key; } } return ans }
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 →
Rust O(n) solution