Clean readable code using HashMaps 
IntuitionApproachComplexity
Time complexity:O(NLogN)

Space complexity:O(n)
Code :Formatted with ChatGpt
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:$$O(NLogN)$$
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:$$O(n)$$
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code : 
Formatted with ChatGpt
```java []
import java.util.*;

class Solution {
    public long maximumCoins(int[][] coins, int k) {
        Arrays.sort(coins, (a, b) -> a[0] - b[0]);
        int n = coins.length;
        long[] prefixSum = new long[n]; // Prefix sum array
        prefixSum[0] = (coins[0][1] - coins[0][0] + 1) * (long) coins[0][2];

        // Build prefix sum array
        for (int i = 1; i < n; i++) {
            prefixSum[i] = prefixSum[i - 1] + (coins[i][1] - coins[i][0] + 1) * (long) coins[i][2];
        }

        TreeMap<Integer, int[]> map = new TreeMap<>(); // Key: left, Value: {right, coins, index}
        for (int i = 0; i < n; i++) {
            map.put(coins[i][0], new int[]{coins[i][1], coins[i][2], i});
        }

        long max = 0;
        // my optimal k window will either end at ith interval or will start from ith interval, the optimal window will never span two intervals paritially
        for (int i = 0; i < n; i++) {
            max = Math.max(max, Math.max(
                value(map, prefixSum, coins[i][1] - k + 1, coins[i][1], false),
                value(map, prefixSum, coins[i][0], coins[i][0] + k - 1, true)
            ));
        }
        return max;
    }

    public long value(TreeMap<Integer, int[]> map, long[] prefixSum, int left, int right, boolean forward) {
        Map.Entry<Integer, int[]> startEntry = map.floorEntry(left) ;
        if (startEntry == null) return 0;

        Map.Entry<Integer, int[]> endEntry =  map.floorEntry(right);
        if (endEntry == null) return 0;

        int startIndex = startEntry.getValue()[2];
        int endIndex = endEntry.getValue()[2];

        long totalCoins = prefixSum[endIndex] - (startIndex > 0 ? prefixSum[startIndex - 1] : 0);

        if (forward) {
            // Adjust for partial interval at the end
            if (endEntry.getValue()[0] > right) {
                long excessLength = endEntry.getValue()[0] - right;
                totalCoins -= excessLength * (long) endEntry.getValue()[1];
            }
        } else {
            // Adjust for partial interval at the start
            if (startEntry.getKey() < left) {
                long excessLength = left - startEntry.getKey();
                totalCoins -= excessLength * (long) startEntry.getValue()[1];
            }
        }

        return totalCoins;
    }
}

```
['Java']