Leetcode Problem 1561. Maximum Number of Coins You Can Get

1561. Maximum Number of Coins You Can Get

Leetcode Solutions

Greedy Approach with Sorting

  1. Sort the array piles in non-decreasing order.
  2. Initialize a variable ans to 0 to store the maximum number of coins we can have.
  3. Iterate over the sorted piles starting from index n to the end of the array, incrementing by 2 each time.
    • Add the value of piles[i] to ans.
  4. Return the value of ans.
UML Thumbnail

Greedy Simulation With Deque

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...