Javascript - Sliding Window
Code
# Code
```javascript []
/**
 * @param {number[][]} coins
 * @param {number} k
 * @return {number}
 */
var maximumCoins = function (coins, k) {
  coins.sort((a, b) => a[0] - b[0]);

  let ans = 0;
  let total = 0;
  let start = 0;
  for (let end = 0; end < coins.length; end++) {
    total += (coins[end][1] - coins[end][0] + 1) * coins[end][2];

    while (coins[end][1] - coins[start][0] + 1 > k) {
      const excess = coins[end][1] - coins[start][0] + 1 - k;
      ans = Math.max(ans, total - excess * coins[end][2]);

      const [left, right, val] = coins[start];
      if (right - left + 1 > excess) {
        total -= excess * val;
        coins[start][0] += excess;
      } else {
        total -= (right - left + 1) * val;
        start++;
      }
    }
    ans = Math.max(ans, total);
  }

  return ans;
};

```
['Sliding Window', 'JavaScript']