diff --git a/src/solution/mod.rs b/src/solution/mod.rs index 9c2e870..6062e7b 100644 --- a/src/solution/mod.rs +++ b/src/solution/mod.rs @@ -1350,3 +1350,4 @@ mod s1786_number_of_restricted_paths_from_first_to_last_node; mod s1787_make_the_xor_of_all_segments_equal_to_zero; mod s1790_check_if_one_string_swap_can_make_strings_equal; mod s1791_find_center_of_star_graph; +mod s1792_maximum_average_pass_ratio; diff --git a/src/solution/s1792_maximum_average_pass_ratio.rs b/src/solution/s1792_maximum_average_pass_ratio.rs new file mode 100644 index 0000000..ae96c09 --- /dev/null +++ b/src/solution/s1792_maximum_average_pass_ratio.rs @@ -0,0 +1,69 @@ +/** + * [1792] Maximum Average Pass Ratio + * + * There is a school that has classes of students and each class will be having a final exam. You are given a 2D integer array classes, where classes[i] = [passi, totali]. You know beforehand that in the i^th class, there are totali total students, but only passi number of students will pass the exam. + * You are also given an integer extraStudents. There are another extraStudents brilliant students that are guaranteed to pass the exam of any class they are assigned to. You want to assign each of the extraStudents students to a class in a way that maximizes the average pass ratio across all the classes. + * The pass ratio of a class is equal to the number of students of the class that will pass the exam divided by the total number of students of the class. The average pass ratio is the sum of pass ratios of all the classes divided by the number of the classes. + * Return the maximum possible average pass ratio after assigning the extraStudents students. Answers within 10^-5 of the actual answer will be accepted. + * + * Example 1: + * + * Input: classes = [[1,2],[3,5],[2,2]], extraStudents = 2 + * Output: 0.78333 + * Explanation: You can assign the two extra students to the first class. The average pass ratio will be equal to (3/4 + 3/5 + 2/2) / 3 = 0.78333. + * + * Example 2: + * + * Input: classes = [[2,4],[3,9],[4,5],[2,10]], extraStudents = 4 + * Output: 0.53485 + * + * + * Constraints: + * + * 1 <= classes.length <= 10^5 + * classes[i].length == 2 + * 1 <= passi <= totali <= 10^5 + * 1 <= extraStudents <= 10^5 + * + */ +pub struct Solution {} + +// problem: https://leetcode.com/problems/maximum-average-pass-ratio/ +// discuss: https://leetcode.com/problems/maximum-average-pass-ratio/discuss/?currentPage=1&orderBy=most_votes&query= + +// submission codes start here + +impl Solution { + pub fn max_average_ratio(classes: Vec>, extra_students: i32) -> f64 { + 0f64 + } +} + +// submission codes end + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + #[ignore] + fn test_1792_example_1() { + let classes = vec![vec![1, 2], vec![3, 5], vec![2, 2]]; + let extra_students = 2; + + let result = 0.78333; + + assert_f64_near!(Solution::max_average_ratio(classes, extra_students), result); + } + + #[test] + #[ignore] + fn test_1792_example_2() { + let classes = vec![vec![2, 4], vec![3, 9], vec![4, 5], vec![2, 10]]; + let extra_students = 4; + + let result = 0.53485; + + assert_f64_near!(Solution::max_average_ratio(classes, extra_students), result); + } +}