Skip to content

Commit 06b57f5

Browse files
authored
Create 1402-reducing-dishes.js
1 parent 502f8e7 commit 06b57f5

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

1402-reducing-dishes.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @param {number[]} satisfaction
3+
* @return {number}
4+
*/
5+
const maxSatisfaction = function (satisfaction, max = 0) {
6+
satisfaction.sort((a, b) => b - a)
7+
for (let j = 1; j <= satisfaction.length; ++j) {
8+
let next = 0
9+
for (let i = 0, k = j; i < j; ++i, --k) next += satisfaction[i] * k
10+
max = Math.max(max, next)
11+
}
12+
return max
13+
}

0 commit comments

Comments
 (0)