Skip to content

Commit 1842d27

Browse files
solves reducing dishes (#1402) in python
1 parent 557eea9 commit 1842d27

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

python/reducing_dishes.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# https://leetcode.com/problems/reducing-dishes/
2+
# T: O(nlogn) where n is the length of satisfaction
3+
# S: O(1)
4+
5+
class Solution:
6+
def maxSatisfaction(self, satisfaction: List[int]) -> int:
7+
satisfaction.sort(reverse = True)
8+
n = len(satisfaction)
9+
presum , res = 0, 0
10+
11+
for i in range(n):
12+
presum += satisfaction[i]
13+
if presum < 0:
14+
break
15+
res = res + presum
16+
17+
return res

0 commit comments

Comments
 (0)