Count Good Meals - Problem
A good meal is a meal that contains exactly two different food items with a sum of deliciousness equal to a power of two.
You can pick any two different foods to make a good meal.
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.
Note: Items with different indices are considered different even if they have the same deliciousness value.
Input & Output
Example 1 — Basic Case
$
Input:
deliciousness = [1,3,5,7,9]
›
Output:
4
💡 Note:
Good meals are: (1,3)→4, (1,7)→8, (3,5)→8, (7,9)→16. All sums are powers of 2.
Example 2 — Duplicates
$
Input:
deliciousness = [1,1,1,3,3,3,7]
›
Output:
12
💡 Note:
Multiple pairs can form same sum: 1+3=4 (9 combinations), 1+7=8 (3 combinations). Total: 9+3=12.
Example 3 — No Valid Pairs
$
Input:
deliciousness = [2,5,11]
›
Output:
1
💡 Note:
Check all pairs: 2+5=7 (not power of 2), 2+11=13 (not power of 2), 5+11=16 (power of 2). So result is 1.
Constraints
- 1 ≤ deliciousness.length ≤ 2 × 104
- 0 ≤ deliciousness[i] ≤ 220
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code