17. Coin Piles
โ GFG solution to the Coin Piles problem: minimize coins removed to maintain difference โค k between any two piles using sliding window technique. ๐
๐งฉ Problem Description
๐ Examples
Example 1
Input: arr[] = [2, 2, 2, 2], k = 0
Output: 0
Explanation: For any two piles the difference in the number of coins is <= 0.
So no need to remove any coin.Example 2
Input: arr[] = [1, 5, 1, 2, 5, 1], k = 3
Output: 2
Explanation: If we remove one coin each from both the piles containing 5 coins,
then for any two piles the absolute difference in the number of coins is <= 3.๐ Constraints
โ
My Approach
Sliding Window with Range Optimization
๐ Time and Auxiliary Space Complexity
๐งโ๐ป Code (C++)
๐งโ๐ป Code (Java)
๐ Code (Python)
๐ง Contribution and Support
๐Visitor Count
Last updated