Talentd
FleetCode

1276. Number of Burgers with No Waste of Ingredients

Medium52.7% acceptance

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

Topics

Hints open one at a time

Hint 1
Can we have an answer if the number of tomatoes is odd ?
Hint 2
If we have answer will be there multiple answers or just one answer ?
Hint 3
Let us define number of jumbo burgers as X and number of small burgers as Y We have to find an x and y in this equation
Hint 4
1. 4X + 2Y = tomato
Hint 5
2. X + Y = cheese
11:40
Still stuck?Read 3 approaches, or watch a walkthrough.
Open solution
Loading editor…
1class Solution:
2 def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:
3
Starter codePython 3Spaces: 4
Examples
Input
16
7
Input
17
4
Input
4
17
Your code is saved on this device.Solution