Skip to content

Commit 8312101

Browse files
committed
2070. Most Beautiful Item for Each Query: RETRY
1 parent 811b680 commit 8312101

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

src/solution/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,3 +1561,4 @@ mod s2064_minimized_maximum_of_products_distributed_to_any_store;
15611561
mod s2065_maximum_path_quality_of_a_graph;
15621562
mod s2068_check_whether_two_strings_are_almost_equivalent;
15631563
mod s2069_walking_robot_simulation_ii;
1564+
mod s2070_most_beautiful_item_for_each_query;
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/**
2+
* [2070] Most Beautiful Item for Each Query
3+
*
4+
* You are given a 2D integer array items where items[i] = [pricei, beautyi] denotes the price and beauty of an item respectively.
5+
* You are also given a 0-indexed integer array queries. For each queries[j], you want to determine the maximum beauty of an item whose price is less than or equal to queries[j]. If no such item exists, then the answer to this query is 0.
6+
* Return an array answer of the same length as queries where answer[j] is the answer to the j^th query.
7+
*
8+
* Example 1:
9+
*
10+
* Input: items = [[1,2],[3,2],[2,4],[5,6],[3,5]], queries = [1,2,3,4,5,6]
11+
* Output: [2,4,5,5,6,6]
12+
* Explanation:
13+
* - For queries[0]=1, [1,2] is the only item which has price <= 1. Hence, the answer for this query is 2.
14+
* - For queries[1]=2, the items which can be considered are [1,2] and [2,4].
15+
* The maximum beauty among them is 4.
16+
* - For queries[2]=3 and queries[3]=4, the items which can be considered are [1,2], [3,2], [2,4], and [3,5].
17+
* The maximum beauty among them is 5.
18+
* - For queries[4]=5 and queries[5]=6, all items can be considered.
19+
* Hence, the answer for them is the maximum beauty of all items, i.e., 6.
20+
*
21+
* Example 2:
22+
*
23+
* Input: items = [[1,2],[1,2],[1,3],[1,4]], queries = [1]
24+
* Output: [4]
25+
* Explanation:
26+
* The price of every item is equal to 1, so we choose the item with the maximum beauty 4.
27+
* Note that multiple items can have the same price and/or beauty.
28+
*
29+
* Example 3:
30+
*
31+
* Input: items = [[10,1000]], queries = [5]
32+
* Output: [0]
33+
* Explanation:
34+
* No item has a price less than or equal to 5, so no item can be chosen.
35+
* Hence, the answer to the query is 0.
36+
*
37+
*
38+
* Constraints:
39+
*
40+
* 1 <= items.length, queries.length <= 10^5
41+
* items[i].length == 2
42+
* 1 <= pricei, beautyi, queries[j] <= 10^9
43+
*
44+
*/
45+
pub struct Solution {}
46+
47+
// problem: https://leetcode.com/problems/most-beautiful-item-for-each-query/
48+
// discuss: https://leetcode.com/problems/most-beautiful-item-for-each-query/discuss/?currentPage=1&orderBy=most_votes&query=
49+
50+
// submission codes start here
51+
52+
impl Solution {
53+
pub fn maximum_beauty(items: Vec<Vec<i32>>, queries: Vec<i32>) -> Vec<i32> {
54+
vec![]
55+
}
56+
}
57+
58+
// submission codes end
59+
60+
#[cfg(test)]
61+
mod tests {
62+
use super::*;
63+
64+
#[test]
65+
#[ignore]
66+
fn test_2070_example_1() {
67+
let items = vec![vec![1, 2], vec![3, 2], vec![2, 4], vec![5, 6], vec![3, 5]];
68+
let queries = vec![1, 2, 3, 4, 5, 6];
69+
70+
let result = vec![2, 4, 5, 5, 6, 6];
71+
72+
assert_eq!(Solution::maximum_beauty(items, queries), result);
73+
}
74+
75+
#[test]
76+
#[ignore]
77+
fn test_2070_example_2() {
78+
let items = vec![vec![1, 2], vec![1, 2], vec![1, 3], vec![1, 4]];
79+
let queries = vec![1];
80+
81+
let result = vec![4];
82+
83+
assert_eq!(Solution::maximum_beauty(items, queries), result);
84+
}
85+
86+
#[test]
87+
#[ignore]
88+
fn test_2070_example_3() {
89+
let items = vec![vec![10, 100]];
90+
let queries = vec![5];
91+
92+
let result = vec![0];
93+
94+
assert_eq!(Solution::maximum_beauty(items, queries), result);
95+
}
96+
}

0 commit comments

Comments
 (0)