[C] sliding window, suffixMax, two ptrs | Time: O(n), Space: O(n)
C []\nint maximizeWin(\n\tconst int * const posArr,\n\tconst int posArrLen,\n\n\tconst int len\n){\n\tassert(posArrLen >= 1 && len >= 0);\n\n\tstruct {\n\t\tint
```C []\nint maximizeWin(\n\tconst int * const posArr,\n\tconst int posArrLen,\n\n\tconst int len\n){\n\tassert(posArrLen >= 1 && len >= 0);\n\n\tstruct {\n\t\tint start;\n\t\tint cnt;\n\t} intervalArr[posArrLen];\n\tint intervalArrLen = 0;\n\tfor (int left = 0, right = 0; left < posArrLen; ){\n\t\twhile (right < posArrLen && posArr[right] <= posArr[left] + len){\n\t\t\tright += 1;\n\t\t}\n\n\t\tintervalArr[intervalArrLen].start = posArr[left];\n\t\tintervalArr[intervalArrLen].cnt = right - left;\n\t\tintervalArrLen += 1;\n\n\t\tconst int leftVal = posArr[left];\n\t\twhile (left < posArrLen && posArr[left] == leftVal){\n\t\t\tleft += 1;\n\t\t}\n\t}\n\n\tint suffixMaxArr[intervalArrLen];\n\tsuffixMaxArr[intervalArrLen - 1] = intervalArr[intervalArrLen - 1].cnt;\n\tfor (int i = intervalArrLen - 2; i >= 0; i -= 1){\n\t\tsuffixMaxArr[i] = suffixMaxArr[i + 1];\n\t\tif (intervalArr[i].cnt > suffixMaxArr[i]){\n\t\t\tsuffixMaxArr[i] = intervalArr[i].cnt;\n\t\t}\n\t}\n\n\tint maxPairSum = 0;\n\tfor (int i = 0, j = 0; i < intervalArrLen; i += 1){\n\t\twhile (j < intervalArrLen && intervalArr[j].start <= intervalArr[i].start + len){\n\t\t\tj += 1;\n\t\t}\n\n\t\tconst int curPairSum = intervalArr[i].cnt +\n\t\t\t( (j < intervalArrLen)? suffixMaxArr[j] : 0 );\n\t\tif (curPairSum > maxPairSum){\n\t\t\tmaxPairSum = curPairSum;\n\t\t}\n\t}\n\treturn maxPairSum;\n}\n```
['C']