Skip to content

Commit 8b459b2

Browse files
authored
Create 2558-take-gifts-from-the-richest-pile.js
1 parent 06ca5eb commit 8b459b2

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @param {number[]} gifts
3+
* @param {number} k
4+
* @return {number}
5+
*/
6+
const pickGifts = function(gifts, k) {
7+
8+
const n = gifts.length
9+
while(k > 0) {
10+
11+
const max = Math.max(...gifts)
12+
const idx = gifts.indexOf(max)
13+
gifts[idx] = ~~(Math.sqrt(max))
14+
15+
k--
16+
}
17+
18+
return gifts.reduce((ac, e) => ac + e, 0)
19+
};

0 commit comments

Comments
 (0)