Migratory Birds

  • + 0 comments

    Rust solution:

    fn birds(arr: &[i32]) -> i32 {
        let mut map = HashMap::new();
    
        for &i in arr {
            *map.entry(i).or_insert(0) += 1;
        }
    
        *map.iter().max_by_key(|(&id, &n)| (n, -id)).unwrap().0
    }