File tree 2 files changed +35
-1
lines changed
2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,369 LeetCode solutions in JavaScript
1
+ # 1,370 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
1192
1192
1558|[ Minimum Numbers of Function Calls to Make Target Array] ( ./solutions/1558-minimum-numbers-of-function-calls-to-make-target-array.js ) |Medium|
1193
1193
1559|[ Detect Cycles in 2D Grid] ( ./solutions/1559-detect-cycles-in-2d-grid.js ) |Medium|
1194
1194
1560|[ Most Visited Sector in a Circular Track] ( ./solutions/1560-most-visited-sector-in-a-circular-track.js ) |Easy|
1195
+ 1561|[ Maximum Number of Coins You Can Get] ( ./solutions/1561-maximum-number-of-coins-you-can-get.js ) |Medium|
1195
1196
1566|[ Detect Pattern of Length M Repeated K or More Times] ( ./solutions/1566-detect-pattern-of-length-m-repeated-k-or-more-times.js ) |Easy|
1196
1197
1576|[ Replace All ?'s to Avoid Consecutive Repeating Characters] ( ./solutions/1576-replace-all-s-to-avoid-consecutive-repeating-characters.js ) |Medium|
1197
1198
1598|[ Crawler Log Folder] ( ./solutions/1598-crawler-log-folder.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 1561. Maximum Number of Coins You Can Get
3
+ * https://leetcode.com/problems/maximum-number-of-coins-you-can-get/
4
+ * Difficulty: Medium
5
+ *
6
+ * There are 3n piles of coins of varying size, you and your friends will take piles of coins as
7
+ * follows:
8
+ * - In each step, you will choose any 3 piles of coins (not necessarily consecutive).
9
+ * - Of your choice, Alice will pick the pile with the maximum number of coins.
10
+ * - You will pick the next pile with the maximum number of coins.
11
+ * - Your friend Bob will pick the last pile.
12
+ * - Repeat until there are no more piles of coins.
13
+ *
14
+ * Given an array of integers piles where piles[i] is the number of coins in the ith pile.
15
+ *
16
+ * Return the maximum number of coins that you can have.
17
+ */
18
+
19
+ /**
20
+ * @param {number[] } piles
21
+ * @return {number }
22
+ */
23
+ var maxCoins = function ( piles ) {
24
+ piles . sort ( ( a , b ) => b - a ) ;
25
+ let result = 0 ;
26
+ const rounds = piles . length / 3 ;
27
+
28
+ for ( let i = 1 ; i < piles . length - rounds ; i += 2 ) {
29
+ result += piles [ i ] ;
30
+ }
31
+
32
+ return result ;
33
+ } ;
You can’t perform that action at this time.
0 commit comments