Test case problem in A : [ 4, 7, -4, 2, 2, 2, 3, -5, -3, 9, -4, 9, -7, 7, -1, 9, 9, 4, 1, -4, -2, 3, -3, -5, 4, -7, 7, 9, -4, 4, -8 ] B : -3


#1

why is the answer 4 8 and not 1 13?!
i mean both are valid,but shouldn’t the answer be in lexicographic order?


#2

It crossed my mind as well, but it’s clearly stated in the problem-
" If multiple solutions exist, output the one where index2 is minimum . If there are multiple solutions with the minimum index2 , choose the one with minimum index1 out of them."


#3

Hi,
Check this:


#4

@rajeshbammidy This solution will fail for test case where same index2 is present for multiple index1 values.
Eg, 2,11,11,-2,15,3,7 and B=9, correct answer will be (2,4) while your code will return (3,4)


#5

Abiding by the constrains wouldn’t the answer be 5 7 ?? or am I missing something??


#6

No, because first of all u have to return index based on 1st index and not zero.
Second thing for same index2 u have to return minimum index 1,
so out of 4,8 || 5,8 || 6,8 u have to return 4,8.
That’s why if u r using hash map and come across the same value of A[i] then skip the loop using continue to get the lowest value of index.