(questions: Vec<i32>)
| 1 | pub fn half_questions(questions: Vec<i32>) -> i32 { |
| 2 | let n = questions.len() / 2; |
| 3 | use std::collections::HashMap; |
| 4 | let mut mmp = HashMap::new(); |
| 5 | for i in questions { *mmp.entry(i).or_insert(0) += 1 } |
| 6 | let mut mmp_vec: Vec<_> = mmp.iter().collect(); |
| 7 | mmp_vec.sort_by(|b, a|a.1.cmp(&b.1)); |
| 8 | let mut ret = 0; |
| 9 | let mut current = 0; |
| 10 | for e in mmp_vec { |
| 11 | ret += 1; |
| 12 | current += e.1; |
| 13 | if current >= n { break } |
| 14 | } |
| 15 | ret |
| 16 | } |
| 17 | |
| 18 | fn main() { |
| 19 | println!("{:?}", half_questions(vec![13,8,3,7,5,6,11,12,3,6,6,11])); |
nothing calls this directly
no outgoing calls
no test coverage detected