Sponsored
Use these hints if you're stuck. Try solving on your own first.
Sort the array.
The problem becomes the following: find maximum subarray A[i … j] such that A[j] - A[i] ≤ 2 * k.
Solve with full IDE support and test cases