Skip to content

Commit d72967e

Browse files
committed
2064. Minimized Maximum of Products Distributed to Any Store: RETRY
1 parent 0fc12d8 commit d72967e

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

src/solution/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,3 +1557,4 @@ mod s2059_minimum_operations_to_convert_number;
15571557
mod s2060_check_if_an_original_string_exists_given_two_encoded_strings;
15581558
mod s2062_count_vowel_substrings_of_a_string;
15591559
mod s2063_vowels_of_all_substrings;
1560+
mod s2064_minimized_maximum_of_products_distributed_to_any_store;
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/**
2+
* [2064] Minimized Maximum of Products Distributed to Any Store
3+
*
4+
* You are given an integer n indicating there are n specialty retail stores. There are m product types of varying amounts, which are given as a 0-indexed integer array quantities, where quantities[i] represents the number of products of the i^th product type.
5+
* You need to distribute all products to the retail stores following these rules:
6+
*
7+
* A store can only be given at most one product type but can be given any amount of it.
8+
* After distribution, each store will have been given some number of products (possibly 0). Let x represent the maximum number of products given to any store. You want x to be as small as possible, i.e., you want to minimize the maximum number of products that are given to any store.
9+
*
10+
* Return the minimum possible x.
11+
*
12+
* Example 1:
13+
*
14+
* Input: n = 6, quantities = [11,6]
15+
* Output: 3
16+
* Explanation: One optimal way is:
17+
* - The 11 products of type 0 are distributed to the first four stores in these amounts: 2, 3, 3, 3
18+
* - The 6 products of type 1 are distributed to the other two stores in these amounts: 3, 3
19+
* The maximum number of products given to any store is max(2, 3, 3, 3, 3, 3) = 3.
20+
*
21+
* Example 2:
22+
*
23+
* Input: n = 7, quantities = [15,10,10]
24+
* Output: 5
25+
* Explanation: One optimal way is:
26+
* - The 15 products of type 0 are distributed to the first three stores in these amounts: 5, 5, 5
27+
* - The 10 products of type 1 are distributed to the next two stores in these amounts: 5, 5
28+
* - The 10 products of type 2 are distributed to the last two stores in these amounts: 5, 5
29+
* The maximum number of products given to any store is max(5, 5, 5, 5, 5, 5, 5) = 5.
30+
*
31+
* Example 3:
32+
*
33+
* Input: n = 1, quantities = [100000]
34+
* Output: 100000
35+
* Explanation: The only optimal way is:
36+
* - The 100000 products of type 0 are distributed to the only store.
37+
* The maximum number of products given to any store is max(100000) = 100000.
38+
*
39+
*
40+
* Constraints:
41+
*
42+
* m == quantities.length
43+
* 1 <= m <= n <= 10^5
44+
* 1 <= quantities[i] <= 10^5
45+
*
46+
*/
47+
pub struct Solution {}
48+
49+
// problem: https://leetcode.com/problems/minimized-maximum-of-products-distributed-to-any-store/
50+
// discuss: https://leetcode.com/problems/minimized-maximum-of-products-distributed-to-any-store/discuss/?currentPage=1&orderBy=most_votes&query=
51+
52+
// submission codes start here
53+
54+
impl Solution {
55+
pub fn minimized_maximum(n: i32, quantities: Vec<i32>) -> i32 {
56+
0
57+
}
58+
}
59+
60+
// submission codes end
61+
62+
#[cfg(test)]
63+
mod tests {
64+
use super::*;
65+
66+
#[test]
67+
#[ignore]
68+
fn test_2064_example_1() {
69+
let n = 6;
70+
let quantities = vec![11, 6];
71+
72+
let result = 3;
73+
74+
assert_eq!(Solution::minimized_maximum(n, quantities), result);
75+
}
76+
77+
#[test]
78+
#[ignore]
79+
fn test_2064_example_2() {
80+
let n = 7;
81+
let quantities = vec![15, 10, 10];
82+
83+
let result = 5;
84+
85+
assert_eq!(Solution::minimized_maximum(n, quantities), result);
86+
}
87+
88+
#[test]
89+
#[ignore]
90+
fn test_2064_example_3() {
91+
let n = 1;
92+
let quantities = vec![100000];
93+
94+
let result = 100000;
95+
96+
assert_eq!(Solution::minimized_maximum(n, quantities), result);
97+
}
98+
}

0 commit comments

Comments
 (0)