Does anyone else consider this problem not accurate

  • 11

    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:

    2-4<=1 check

    1-0<=1 check

    return 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.

  • -3

    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!

  • 1

    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.

  • -1

    Oh, sorry, it should be false! because 4 - 2 > 1

  • 1

    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?

  • -2

    =.=OK I see your point.....don't care about the detail...

  • 0

    yes, I have same question as yours regards test cases of [4,2], 1, 1 and [-1,-1], 1, -1

  • 0

    I think it doesn't make sense if t < 0. So just make sure that t >= 0 and abs(nums[j] - nums[i]) <= t.

  • 1

    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

  • 0

    @KandL said in Does anyone else consider this problem not accurate:

    [-1,-1], 1, -1

    Agreed. Test case [-1,-1], 1, -1 troubles me.

  • 0

    You should understand "absolute difference" first.

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.