# Pairwise - Rules and examples contradict each other

Pairwise - Rules and examples contradict each other
0
#1

The rules for the front-end development’s advanced algorithm scripting problem “Pairwise” state:

If multiple pairs are possible that have the same numeric elements but different indices, return the smallest sum of indices. Once an element has been used, it cannot be reused to pair with another.

But one of the examples states: pairwise([0, 0, 0, 0, 1, 1], 1) should return 10, which contradicts the above bolded statement. If, when presented with pairs that have the same numeric elements but different indices, you’re only supposed to keep the pair with the smallest sum of indices, then you would only keep the pair [0,1] from indices 0 and 4 and discard the pair [0,1] from indices 1 and 5. This would leave you with a single pair whose indices sum to 4.

0 Likes

#2

This one trips some people. I had to read it carefully a couple times to see why it’s 10. (Although the way that you are interpreting it is a little different than the way that I’ve seen most people get hung up.)

The part you have highlighted doesn’t mean that if you have two different complete pairs, that you only keep one. It means that if there are two different ways to make a pair, then use the combination with the smallest index.

So, `pairwise([1, 1, 2], 3)` would be `2` because you choose the `1` at index `0`, but `pairwise([1, 1, 2, 2], 3)` would be `6` because you can make two complete pairs.

0 Likes

#3

I see - so it’s saying that in [1,1, 2], 3 to use 0 and 2 rather than 1 and 2 because the sum of 0 and 2 is lower than 1 and 2.

It might be a good idea to add an example like yours with [1, 1, 2], 3 to the instructions to clarify that when it says “same numeric elements but different indices” it’s referring to being able to pair indice a, b, c, etc. with indice y to reach arg and choosing which of a, b, c to use. As it’s written now “multiple pairs are possible that have the same numeric elements but different indices” seems open to interpretation: both of our examples refer to “multiple pairs that have the same numeric elements but different indices”.

Thank you so much for the clarification!

0 Likes

#4

Feel free to suggest an additional test case like that in a GitHub Issue (you could even contribute the fix yourself!)

1 Like