Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn main() {
- println!("{}", equalize(vec![3,3,2,1,3])); // 2
- println!("{}", equalize(vec![1,2,5,4,6,3])); // 5
- }
- fn equalize(mut list: Vec<i32>) -> u32 {
- // Get the maximum occurring element
- let max_ele = match list.iter().max_by_key(|&x| list.iter().filter(|&a| a == x).count()) {
- Some(e) => e,
- None => return (list.len() -1) as u32,
- };
- // Filter out the remaining and count
- list.iter().filter(|&x| x != max_ele).count() as u32
- }
Add Comment
Please, Sign In to add comment