Skip to content

Commit 0592897

Browse files
authored
Create 3075-maximize-happiness-of-selected-children.js
1 parent a1d929a commit 0592897

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @param {number[]} happiness
3+
* @param {number} k
4+
* @return {number}
5+
*/
6+
var maximumHappinessSum = function(happiness, k) {
7+
happiness.sort((a, b) => b - a)
8+
let ans = 0
9+
for (let i = 0; i < k; i++) {
10+
ans += Math.max(happiness[i] - i, 0)
11+
}
12+
return ans
13+
};

0 commit comments

Comments
 (0)