1711. Count Good Meals Medium

@problem@discussion
#Array#Hash Table



1/**
2 * [1711] Count Good Meals
3 *
4 * A good meal is a meal that contains exactly two different food items with a sum of deliciousness equal to a power of two.
5 * You can pick any two different foods to make a good meal.
6 * Given an array of integers deliciousness where deliciousness[i] is the deliciousness of the i^​​​​​​th​​​​​​​​ item of food, return the number of different good meals you can make from this list modulo 10^9 + 7.
7 * Note that items with different indices are considered different even if they have the same deliciousness value.
8 *  
9 * Example 1:
10 * 
11 * Input: deliciousness = [1,3,5,7,9]
12 * Output: 4
13 * Explanation: The good meals are (1,3), (1,7), (3,5) and, (7,9).
14 * Their respective sums are 4, 8, 8, and 16, all of which are powers of 2.
15 * 
16 * Example 2:
17 * 
18 * Input: deliciousness = [1,1,1,3,3,3,7]
19 * Output: 15
20 * Explanation: The good meals are (1,1) with 3 ways, (1,3) with 9 ways, and (1,7) with 3 ways.
21 *  
22 * Constraints:
23 * 
24 * 	1 <= deliciousness.length <= 10^5
25 * 	0 <= deliciousness[i] <= 2^20
26 * 
27 */
28pub struct Solution {}
29
30// problem: https://leetcode.com/problems/count-good-meals/
31// discuss: https://leetcode.com/problems/count-good-meals/discuss/?currentPage=1&orderBy=most_votes&query=
32
33// submission codes start here
34
35impl Solution {
36    pub fn count_pairs(deliciousness: Vec<i32>) -> i32 {
37        0
38    }
39}
40
41// submission codes end
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46
47    #[test]
48    fn test_1711() {
49    }
50}
51


Back
© 2025 bowen.ge All Rights Reserved.