educative.io

Understanding expected outcome

{-1,0,2,3) target = 3
why is the answer 2? should’nt it be 5? The question states not to re-use the same index in a single combo. The same index can be re-used in different combos, rite? which of the follow combos are invalid answers?
possible combos are
-1,0,2 < 3
-1,0,3 <3
-1,2,3
0,-1,2 <3
0,2,3
2,-1,0 <3
2,0,3
3,-1,0 <3
3,0,2


Course: Grokking the Coding Interview: Patterns for Coding Questions - Learn Interactively
Lesson: Triplets with Smaller Sum (medium) - Grokking the Coding Interview: Patterns for Coding Questions

Hi @bee1
The correct answer is 2 because the question states that not re-use the same index in a single combo means the permutation of a combo is also considered as a single combo. For example
{-1,0,2}, {0,-1,2}, {2,-1,0}, {2,0,-1} => all considered as a single combo.
That is why the correct answer is 2.
I hope this will help