Skip to content

Commit d538be3

Browse files
authored
Create number-of-burgers-with-no-waste-of-ingredients.py
1 parent 6a2b456 commit d538be3

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Time: O(1)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def numOfBurgers(self, tomatoSlices, cheeseSlices):
6+
"""
7+
:type tomatoSlices: int
8+
:type cheeseSlices: int
9+
:rtype: List[int]
10+
"""
11+
# let the number of jumbo burger be x, the number of small burger be y:
12+
# 4x + 2y = t
13+
# x + y = c
14+
# =>
15+
# x = t/2-c
16+
# y = 2c-t/2
17+
# since x, y are natural numbers
18+
# => t/2 is integer, t/2-c >= 0, 2c-t/2 >= 0
19+
# => t%2 == 0, 2c <= t <= 4c
20+
return [tomatoSlices//2-cheeseSlices, 2*cheeseSlices - tomatoSlices//2] \
21+
if tomatoSlices%2 == 0 and 2*cheeseSlices <= tomatoSlices <= 4*cheeseSlices \
22+
else []

0 commit comments

Comments
 (0)