Leetcode 1683 Solution

This article provides solution to leetcode question 1683 (maximum-number-of-coins-you-can-get)

https://leetcode.com/problems/maximum-number-of-coins-you-can-get

Solution

class Solution:
    def maxCoins(self, piles: List[int]) -> int:
        piles.sort(reverse=True)

        i = 1
        cnt = 0
        ans = 0

        while cnt < len(piles) // 3:
            ans += piles[i]
            cnt += 1
            i += 2

        return ans