Skip to content

Commit aeda7fc

Browse files
author
hasibulislam999
committed
Maximum Number of Coins You Can Get problem solved
1 parent 4a57681 commit aeda7fc

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Title: Maximum Number of Coins You Can Get
3+
* Description: Given an array of integers piles where piles[i] is the number of coins in the ith pile.
4+
* Author: Hasibul Islam
5+
* Date: 06/05/2023
6+
*/
7+
8+
/**
9+
* @param {number[]} piles
10+
* @return {number}
11+
*/
12+
var maxCoins = function (piles) {
13+
piles.sort((a, b) => a - b);
14+
let j = piles.length - 2,
15+
ans = 0;
16+
for (let i = 0; i < piles.length / 3; i++) {
17+
ans += piles[j];
18+
j = j - 2;
19+
}
20+
return ans;
21+
};

0 commit comments

Comments
 (0)