Javascript | Sliding Window | O(n)
Code
# Code
```javascript []
/**
 * @param {number[][]} coins
 * @param {number} k
 * @return {number}
 */
var maximumCoins = function(coins, k) {
    const n = coins.length;
    function solve(A){
        A.sort((a,b) => a[0] - b[0]);
        let res = 0, cur = 0, i = 0;
        for(let j = 0; j < A.length; j++){
            const [l,r,c] = A[j];
            cur += (r - l + 1)*c;
            while(A[j][1] - A[i][1] + 1 > k){
                cur -= (A[i][1] - A[i][0] + 1)*A[i][2];
                i++;
            }
            part = Math.max(0, A[j][1] - A[i][0] + 1 - k)*A[i][2];
            res = Math.max(res, cur - part);
        }
        return res;
    }
    let res = solve(coins);
    for(let i = 0; i < coins.length; ++i){
        const [l,r,c] = coins[i];
        coins[i] = [-r, -l, c];
    }
    return Math.max(res, solve(coins));
    
};
```
['JavaScript']