You are viewing a single comment's thread. Return to all comments →
RUST:
fn missingNumbers(arr: &[i32], brr: &[i32]) -> Vec<i32> { let mut count_arr: HashMap<i32,i32> = HashMap::new(); let mut count_brr: HashMap<i32,i32> = HashMap::new(); let mut result: Vec<i32> = Vec::new(); for num in arr { count_arr.entry(*num).and_modify(|c| *c+=1).or_insert(1); } for num in brr { count_brr.entry(*num).and_modify(|c| *c+=1).or_insert(1); } for (num, _) in &count_brr { if count_brr.get(&num).unwrap_or(&0) > count_arr.get(&num).unwrap_or(&0) { result.push(*num); } } result.sort(); result }
Seems like cookies are disabled on this browser, please enable them to open this website
I agree to HackerRank's Terms of Service and Privacy Policy.
Missing Numbers
You are viewing a single comment's thread. Return to all comments →
RUST: