Pairwise question

Pairwise question
0.0 0

#1

I have been studying the Pairwise problem description and looked over the tests and expected results.

I must be missing something, but I can not understand how the following test is valid:

pairwise([0, 0, 0, 0, 1, 1], 1) should return 10

My thinking if I take the first zero (index = 0) and pair it with the 1st one (index 4), the sum should be 4. Even if I chose the 4th zero (index = 3) and pair it with the last zero (index 5), the sum would still only be 8.

Also, the problem description says “Once an element has been used, it cannot be reused to pair with another.” Does “used” mean used in a pair or attempted to use in a pair?

Obviously, I am not understanding the problem description. Any insight would be great.

Thanks,
Randell


#2

So,
pairwise([0, 0, 0, 0, 1, 1], 1) should return 10.

What I think you’re missing is that you can have more than one pair.

You take the first 0 and the first 1 --> 0+4=4
You take the second 0 and the second 1 --> 1+5=6
Then, 4+6=10

You need to add all sums, and always use first the ones with lower index.


#3

Actually, I saw the extra pair, but I was interpreting the following problem statement differently. I originally thought it meant when multiples of same elements existed, only use the pair which had the smallest sum. So, that is why I was thinking it should be four.

If multiple pairs are possible that have the same numeric elements but different indices, return the smallest sum of indices.