The problem statement:
Given an array of integers, find out whether there are two distinct indices i and j in the array such that the difference between nums[i] and nums[j] is at most t and the difference between i and j is at most k.
So then if the following are true then return true:
nums[i] - nums[j] <=t and
Then [4,2], 1,1 should be true:
So then you have to assume what they're asking for is:
abs(nums[i] - nums[j]) <=t and
but then I propose the question of why offer a possible scenario of t<0.
Either way, this problem is not correct as written.
I don't think so! The problem is ACCURATE!
In the problem, it does NOT state i > j or j > i.
Therefore, either could be true!
In your example, [4, 2], 1, 1
let i = 1 and j = 0, we get it correct!
if i =1, j=0, the function should return true, but the solution set rejects true and expects false, which leads me to conclude the problem is incorrectly stated.
Define i =1, j = 0, then the difference between nums[i] and nums[j] is 2-4 = -2, which is less than t = 1, and since i-j <=1, then the answer should be TRUE, based on the way the problem is worded.
Hence this problem is inaccurate
Do you see my point?
yes, I have same question as yours regards test cases of [4,2], 1, 1 and [-1,-1], 1, -1
I think it doesn't make sense if t < 0. So just make sure that t >= 0 and abs(nums[j] - nums[i]) <= t.
I too agree. It is very confusing. I don't know why are they giving t values as negative in the test cases. It does not align with instructions in the question. Seems like we should dig more information from the test cases rather than problem statement :-D
[-1,-1], 1, -1
Agreed. Test case [-1,-1], 1, -1 troubles me.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.