We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4a57681 commit aeda7fcCopy full SHA for aeda7fc
Game Theory/1561_maximum-number-of-coins-you-can-get.js
@@ -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