How two pointer can solve this?

Given an Array of N elements we have to find the largest range of [L,R] such that the difference between the largest and the smallest element in the range is at most D.

run a loop from R to n , check the difference between arr[i-1]and arr[i-n] while updating the result.

I think you didn’t got it. Let me explain you.

It says we have to find the maximum length of subarray in which the difference of minimum and maximum is less than equal to given constant D.

Or you can say L and R both are variable.