input: [5, 3, 1, 3, 0, 9]
target: 5
isn’t the output for this input is 4? the solution gave 6. Is it because the input might have multiple solutions and the program returns triplet with smallest sum?
Thank you
input: [5, 3, 1, 3, 0, 9]
target: 5
isn’t the output for this input is 4? the solution gave 6. Is it because the input might have multiple solutions and the program returns triplet with smallest sum?
Thank you
Hi Chris, you are absolutely right. Using their approach, if the array is sorted, we would come across the triplet 0, 1, 5 before 0, 1, 3 and so the solution is 0, 1, 5 according to their code. Their solution does not account for the triplet with smallest sum when the absolute distance between the target and multiple triplets are the same.
I see. hmm, it confused me for a while hahaha
Looks like they since fixed this issue, currently line 18 and 19. That said there’s a duplicate condition on lines 13-15 as of today, 2 separate checks for smallest_difference with the same condition.