1276. Number of Burgers with No Waste of Ingredients LeetCode Solution
In this guide, you will get 1276. Number of Burgers with No Waste of Ingredients LeetCode Solution with the best time and space complexity. The solution to Number of Burgers with No Waste of Ingredients problem is provided in various programming languages like C++, Java, and Python. This will be helpful for you if you are preparing for placements, hackathons, interviews, or practice purposes. The solutions provided here are very easy to follow and include detailed explanations.
Table of Contents
- Problem Statement
- Complexity Analysis
- Number of Burgers with No Waste of Ingredients solution in C++
- Number of Burgers with No Waste of Ingredients solution in Java
- Number of Burgers with No Waste of Ingredients solution in Python
- Additional Resources

Problem Statement of Number of Burgers with No Waste of Ingredients
Given two integers tomatoSlices and cheeseSlices. The ingredients of different burgers are as follows:
Jumbo Burger: 4 tomato slices and 1 cheese slice.
Small Burger: 2 Tomato slices and 1 cheese slice.
Return [total_jumbo, total_small] so that the number of remaining tomatoSlices equal to 0 and the number of remaining cheeseSlices equal to 0. If it is not possible to make the remaining tomatoSlices and cheeseSlices equal to 0 return [].
Example 1:
Input: tomatoSlices = 16, cheeseSlices = 7
Output: [1,6]
Explantion: To make one jumbo burger and 6 small burgers we need 4*1 + 2*6 = 16 tomato and 1 + 6 = 7 cheese.
There will be no remaining ingredients.
Example 2:
Input: tomatoSlices = 17, cheeseSlices = 4
Output: []
Explantion: There will be no way to use all ingredients to make small and jumbo burgers.
Example 3:
Input: tomatoSlices = 4, cheeseSlices = 17
Output: []
Explantion: Making 1 jumbo burger there will be 16 cheese remaining and making 2 small burgers there will be 15 cheese remaining.
Constraints:
0 <= tomatoSlices, cheeseSlices <= 107
Complexity Analysis
- Time Complexity:
- Space Complexity:
1276. Number of Burgers with No Waste of Ingredients LeetCode Solution in C++
class Solution {
public:
vector<int> numOfBurgers(int tomatoSlices, int cheeseSlices) {
if (tomatoSlices % 2 == 1 || tomatoSlices < 2 * cheeseSlices ||
tomatoSlices > cheeseSlices * 4)
return {};
int jumboBurgers = (tomatoSlices - 2 * cheeseSlices) / 2;
return {jumboBurgers, cheeseSlices - jumboBurgers};
}
};
/* code provided by PROGIEZ */
1276. Number of Burgers with No Waste of Ingredients LeetCode Solution in Java
class Solution {
public List<Integer> numOfBurgers(int tomatoSlices, int cheeseSlices) {
if (tomatoSlices % 2 == 1 || tomatoSlices < 2 * cheeseSlices || tomatoSlices > cheeseSlices * 4)
return new ArrayList<>();
int jumboBurgers = (tomatoSlices - 2 * cheeseSlices) / 2;
return List.of(jumboBurgers, cheeseSlices - jumboBurgers);
}
}
// code provided by PROGIEZ
1276. Number of Burgers with No Waste of Ingredients LeetCode Solution in Python
class Solution:
def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> list[int]:
if tomatoSlices % 2 == 1 or tomatoSlices < 2 * cheeseSlices or tomatoSlices > cheeseSlices * 4:
return []
jumboBurgers = (tomatoSlices - 2 * cheeseSlices) // 2
return [jumboBurgers, cheeseSlices - jumboBurgers]
# code by PROGIEZ
Additional Resources
- Explore all LeetCode problem solutions at Progiez here
- Explore all problems on LeetCode website here
Happy Coding! Keep following PROGIEZ for more updates and solutions.