Clean code....looks pretty....nicely commented
IntuitionThe required answer can only be found if we choose start point of all intervals or the end points of all intervalsApproachUsing sliding window,once fro
# Intuition
The required answer can only be found if we choose start point of all intervals or the end points of all intervals

# Approach
Using sliding window,once from front side and then from back side,taking max of both

# Complexity
- Time complexity:
O(nlogn)

- Space complexity:
O(1)

# Code
```cpp []
#define ll long long
class Solution {
public:
    long long maximumCoins(vector<vector<int>>& coins, int k) {
        ll n = coins.size();
        sort(coins.begin(), coins.end());
        ll ans = 0, sum = 0;
        
        // Forward pass
        for(ll i = 0, j = 0; i < n; i++) {
            ll endingPoint = coins[i][0] + k - 1;
            //adding contribution of full interval till its possible to do so
            while(j < n && coins[j][1] <= endingPoint) {
                ll intervalStart = coins[j][0];
                ll intervalEnd = coins[j][1];
                ll score = coins[j][2];
                sum += (intervalEnd - intervalStart + 1) * score;
                j++;
            }
            //adding partial sum from the next interval,in case we cant add full interval
            ll partialSum;
            if(j <= n) { 
                if(j < n) {  
                    ll intervalStart = coins[j][0];
                    ll intervalEnd = coins[j][1];
                    ll score = coins[j][2];
                    partialSum = max(0LL, endingPoint - intervalStart + 1) * score;
                    sum += partialSum;
                }
                ans = max(ans, sum);  
                if(j < n) sum -= partialSum;  
            }
            //removing the contribution of current start interval before going to next interval start point
            ll currentIntervalStart = coins[i][0];
            ll currentIntervalEnd = coins[i][1];
            ll currentIntervalScore = coins[i][2];
            sum -= (currentIntervalEnd - currentIntervalStart + 1) * currentIntervalScore;
        }
        
        // Backward pass (same changes as forward pass)
        sum = 0;
        for(ll i = n-1, j = n-1; i >= 0; i--) {
            ll endingPoint = coins[i][1] - k + 1;
            //adding contribution of full interval till its possible to do so
            while(j >= 0 && coins[j][0] > endingPoint) {
                ll intervalStart = coins[j][0];
                ll intervalEnd = coins[j][1];
                ll score = coins[j][2];
                sum += (intervalEnd - intervalStart + 1) * score;
                j--;
            }
             //adding partial sum from the next interval,in case we cant add full interval
            ll partialSum;
            if(j >= -1) { 
                if(j >= 0) { 
                    ll intervalStart = coins[j][0];
                    ll intervalEnd = coins[j][1];
                    ll score = coins[j][2];
                    partialSum = max(0LL, intervalEnd - endingPoint + 1) * score;
                    sum += partialSum;
                }
                ans = max(ans, sum);  
                if(j >= 0) sum -= partialSum; 
            }
            //removing the contribution of current start interval before going to next interval start point
            ll currentIntervalStart = coins[i][0];
            ll currentIntervalEnd = coins[i][1];
            ll currentIntervalScore = coins[i][2];
            sum -= (currentIntervalEnd - currentIntervalStart + 1) * currentIntervalScore;
        }
        return ans;
    }
};
```
['C++']