def indicesAtGivenDistance(nums, n, k, m):

# Write your code here

# Return a list containing two integers denoting the pair of valid indices.

# You can return the indices in any order

#

#--------------------------------------------------------------------------

#

# Approach 1 only passed 8/10 TestCases

#

#for i in range(0,n):

# for j in range(i+1,n):

# if(abs(nums[i]-nums[j])<=m and abs(i-j)<=k):

# return(i,j)

#

#--------------------------------------------------------------------------

#

# Approach 2 More Efficient solution passed 10/10 TestCases

#

i=0

j=n-1

while(i<j):

v=abs(nums[i]-nums[j])

if(v<=m and abs(i-j)<=k):

return(i,j)

elif(v>m):

j-=1

else:

i+=1

return[0,0]

#---------------------------------------------------------------------------