TARGET DECK: Leetcode FILE TAGS: Medium


Intuition

  • I misunderstood the question.
  • The question, when saying “Bob will get the last one” means Bob will get the minimum one of the whole array.
  • So it is as simple as sorting and then getting every 2nd maximum.

Complexity

Runtime

due to sorting.

Space

due to in place sorting.

Code

class Solution:
    def maxCoins(self, piles: List[int]) -> int:
        piles.sort()
        n = len(piles)
        res = 0
        for i in range(n // 3, n, 2):
            res += piles[i]
        return res

Notes

Cards

START Basic Front: Maximum Number Of Coins You Can Get Back: Bob will get the last one means Bob will get the minimum of the remaining.

END


References