[LeetCode] Number of Burgers with No Waste of Ingredients

1276. 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 [].

1
2
3
4
5
6
7
8
9
10
11
12
class Solution {
public:
vector<int> numOfBurgers(int A, int B) {
if(B * 4ll < A or A & 1) return {};
int jumbo = 0, small = B;
A -= B * 2;
if(A < 0 or A & 1) return {};
jumbo += A / 2;
small -= jumbo;
return {jumbo, small};
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2022/08/24/PS/LeetCode/number-of-burgers-with-no-waste-of-ingredients/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.