Skip to content

Commit 523e709

Browse files
committed
1792. Maximum Average Pass Ratio: RETRY
1 parent 584ad87 commit 523e709

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

src/solution/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,3 +1350,4 @@ mod s1786_number_of_restricted_paths_from_first_to_last_node;
13501350
mod s1787_make_the_xor_of_all_segments_equal_to_zero;
13511351
mod s1790_check_if_one_string_swap_can_make_strings_equal;
13521352
mod s1791_find_center_of_star_graph;
1353+
mod s1792_maximum_average_pass_ratio;
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* [1792] Maximum Average Pass Ratio
3+
*
4+
* 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.
5+
* 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.
6+
* 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.
7+
* Return the maximum possible average pass ratio after assigning the extraStudents students. Answers within 10^-5 of the actual answer will be accepted.
8+
*
9+
* Example 1:
10+
*
11+
* Input: classes = [[1,2],[3,5],[2,2]], extraStudents = 2
12+
* Output: 0.78333
13+
* 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.
14+
*
15+
* Example 2:
16+
*
17+
* Input: classes = [[2,4],[3,9],[4,5],[2,10]], extraStudents = 4
18+
* Output: 0.53485
19+
*
20+
*
21+
* Constraints:
22+
*
23+
* 1 <= classes.length <= 10^5
24+
* classes[i].length == 2
25+
* 1 <= passi <= totali <= 10^5
26+
* 1 <= extraStudents <= 10^5
27+
*
28+
*/
29+
pub struct Solution {}
30+
31+
// problem: https://leetcode.com/problems/maximum-average-pass-ratio/
32+
// discuss: https://leetcode.com/problems/maximum-average-pass-ratio/discuss/?currentPage=1&orderBy=most_votes&query=
33+
34+
// submission codes start here
35+
36+
impl Solution {
37+
pub fn max_average_ratio(classes: Vec<Vec<i32>>, extra_students: i32) -> f64 {
38+
0f64
39+
}
40+
}
41+
42+
// submission codes end
43+
44+
#[cfg(test)]
45+
mod tests {
46+
use super::*;
47+
48+
#[test]
49+
#[ignore]
50+
fn test_1792_example_1() {
51+
let classes = vec![vec![1, 2], vec![3, 5], vec![2, 2]];
52+
let extra_students = 2;
53+
54+
let result = 0.78333;
55+
56+
assert_f64_near!(Solution::max_average_ratio(classes, extra_students), result);
57+
}
58+
59+
#[test]
60+
#[ignore]
61+
fn test_1792_example_2() {
62+
let classes = vec![vec![2, 4], vec![3, 9], vec![4, 5], vec![2, 10]];
63+
let extra_students = 4;
64+
65+
let result = 0.53485;
66+
67+
assert_f64_near!(Solution::max_average_ratio(classes, extra_students), result);
68+
}
69+
}

0 commit comments

Comments
 (0)