Sliding Window. Same as 2271, but in both ways
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

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

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

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

# Code
```python3 []
class Solution:
    def maximumCoins(self, tiles: List[List[int]], carpetLen: int) -> int:

        tiles.sort()
        print(tiles)
        # return

        mx = 0
        l = 0
        r = 0
        cr = 0
        cover = carpetLen + tiles[r][0] - 1
        while r < len(tiles):
            
            if cover >= tiles[r][1]:
                cr += (tiles[r][1] - tiles[r][0] + 1) * tiles[r][2]
                mx = max(cr, mx)
                r += 1
            else:
                if cover >= tiles[r][0]:
                    # cr += (cover - tiles[r][0] + 1)
                    mx = max(cr + ((cover - tiles[r][0] + 1) * tiles[r][2]), mx)
                # else:
                cr -= (tiles[l][1] - tiles[l][0] + 1) * tiles[l][2]
                l += 1
                if l >= len(tiles): break
                cover = tiles[l][0] + carpetLen - 1

        print
        
        # tiles.sort(reverse=True)
        l = len(tiles) - 1
        r = len(tiles) - 1
        cr = 0
        cover = tiles[r][1] - carpetLen + 1
        while r >= 0:
            
            if cover <= tiles[r][0]:
                cr += (tiles[r][1] - tiles[r][0] + 1) * tiles[r][2]
                mx = max(cr, mx)
                r -= 1
            else:
                if cover <= tiles[r][1]:
                    # cr += (cover - tiles[r][0] + 1)
                    mx = max(cr + ((tiles[r][1] - cover + 1) * tiles[r][2]), mx)
                # else:
                cr -= (tiles[l][1] - tiles[l][0] + 1) * tiles[l][2]
                l -= 1
                if l < 0: break
                cover = tiles[l][1] - carpetLen + 1

        # print(mx)
        # return mx
        return mx















        # start = []
        # end = []
        # mxx = 0
        # for i, j, c in coins:
        #     heapq.heappush(start, (i, c))
        #     heapq.heappush(end, (max(j + 1, i + k), c))
        #     mxx = max(mxx, j + 1)


        # # arr = [0] * (mxx + k)
        # print(start, end)
        
        # mx = 0
        # cn = 0
        # cnt = 0
        # # print(arr, mxx)
        # for i in range(start[0][0], start[0][0] + k):
        #     while start and start[0][0] <= i:
        #         cn += heapq.heappop(start)[1]
        #         # cnt += 1
        #     while end and end[0][0] <= i:
                
        #         cn = -heapq.heappop(end)[1]
        #     print(i, cn)
        #     # arr[i] = cn
        #     mx += cn
        #     # print(i)

        # print(mx, mxx, i, "----" )
        # ans = 0
        # ans = max(mx, ans)

        # return
        
        # for j in range(i + 1, mxx + 1):
        #     while start and start[0][0] <= j:
        #         cn = heapq.heappop(start)[1]
        #         cnt += 1
        #     while end and end[0][0] <= j:
        #         heapq.heappop(end)
        #         cnt -= 1
        #         if cnt == 0: cn = 0
        #         # if cnt - 1 == 0:
        #         #     cn = 0
        #         # cn = 0
        #     # arr[j] = cn
        #     mx += cn - arr[j - k]
        #     ans = max(ans, mx)
        #     # print(j, mx, cn, cnt)

        # # print(arr, ans)
        # return ans
        
        
```
['Python3']