Sliding Window using pure C not C++
IntuitionThere is just one observation/inutition: (whatever)
Either the window is starting at Li or ending at Ri. (optimal)
In those cases you can get more coin
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
There is just one observation/inutition: (whatever)
- Either the window is starting at `Li` or ending at `Ri`. (optimal)
- In those cases you can get more coins.
- You can't check just `Li` positions. Because each interval have different coins. If they have same coin values then only checking `Li` will be sufficient.
- But, in this case each interval have different values, so you have to check for both `Li` and `Ri`. (starting and ending)

# Approach
<!-- Describe your approach to solving the problem. -->
- Sort 2d array based on increasing interval (intervals are nonoverlapping).
- Forward Pass: checks all `Li`.
  - In this pass, for each i, I will find the j and calculate how much coins we can gather.
  - remember to count regular intervals and partial intervals separately, otherwise you will be in pain later. (like me.)
  - Make sure to shrink window perfectly. In each interval substract whoe left i interval. Because as we move to right.. left most is obsoleted.
- Backward Pass: Checks all `Ri`
  - Start i from n -1 to 0 in backward manner. Exact opposite of forward pass.
  - for each i we have to find j and calculate corresponding coins that we can collect.
  - Like above, make sure to calculate regular intervals and partial intervals separately.
  - And shrink window carefully. Like above..

- In each iteration of forward/backward pass we calculate the `max_coins`.
- Remember to calculate `max_coins` before shrinking window. Because `coin_count` will be subtracted after shrinking of the window.

# Complexity
- Time complexity:
nlogn for qsort and almost 2n for two passes.
- Space complexity:
constant space
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# IMP
Please don't post/encourage solutions tagging as C if you're solving it using CPP. 
PLEASE...
# Code
```c []
#define ll long long
#define max(a, b) ((a) > (b) ? (a) : (b))
int compare(const void* a, const void* b)
{
    //return (*(const int (*)[3])a)[0] - (*(const int (*)[3])b)[0];
    return (*(int **)a)[0] - (*(int **)b)[0];
}

long long maximumCoins(int** coins, int coinsSize, int* coinsColSize, int k) {
    //sort the array
    int n = coinsSize;
    qsort(coins, n, sizeof(coins[0]), compare);
    
    

    ll max_coins = 0, coin_count = 0;

    // Forward Pass
    for (int i = 0, j = 0; i < n; i++) {
        int target = coins[i][0] + k - 1;

        while (j < n && coins[j][1] <= target) {
            int l = coins[j][0], r = coins[j][1], c =coins[j][2];
            int count = r - l + 1;
            coin_count += (ll) count * c;
            j++;
        }
        int partial = 0; //make sure to calculate this separate
        if (j < n && coins[j][0] <= target) {
            partial = (ll)(target-coins[j][0]+1) * coins[j][2];
        }

        max_coins = max(max_coins, coin_count+partial);
        int l = coins[i][0], r = coins[i][1], c = coins[i][2];
        coin_count -= (ll)(r-l+1) * c;
    }
    coin_count = 0;
    //Backward Pass
    for (int i = n-1, j = i; i >= 0; i--) {
        int target = coins[i][1] - k + 1;
        while (j >= 0 && coins[j][0] >= target) {
            int l = coins[j][0], r = coins[j][1], c = coins[j][2];
            int count = (r - l + 1);
            coin_count += (ll)count * c;
            j--;
        }
        int partial = 0; //separately calculate
        if (j >= 0 && coins[j][1] >= target) {
            partial = (ll)(coins[j][1] - target + 1) * coins[j][2];
        }
        max_coins = max(max_coins, coin_count + partial);
        int l = coins[i][0], r = coins[i][1], c = coins[i][2];
        coin_count -= (ll)(r-l+1) * c;
    }
    return max_coins;
}
```
['C']