educative.io

Educative

I != j != k Condition Not Met

The problem states i != j != k. Wouldn’t we need to de-duplicate the array before counting?

I don’t see how the current solution guarantees not counting duplicated numbers. Thank you.

We don’t need to find three different numbers. ‘i’, ‘j’, and ‘k’ are indices here, so we just need to have three numbers from the array, these numbers can all be same:

count all triplets in it such that arr[i] + arr[j] + arr[k] < target where i , j , and k are three different indices.

1 Like

But your question contradicts the solution.

in the solution, you’ve mentioned:
“make sure that each number is not used more than once.”

and in the above comment, you’ve mentioned:
“we just need to have three numbers from the array, these numbers can all be same

@qqq: There are two things discussed here: 1) Indices, and 2) numbers pointed by these indices. The problem states that the indices need to be different (i.e., i != j != k) but the numbers pointed out by these indices could all be same, as there could be repeating numbers in the array.