Freecodecamp: Pairwise Language Clarification

Created on 28 Feb 2018  路  4Comments  路  Source: freeCodeCamp/freeCodeCamp



Challenge Name

Pairwise: https://www.freecodecamp.org/challenges/pairwise

Issue Description

The phrasing of the rule: "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." could be interpreted multiple ways, for example:

1) If you have multiple indices a, b, c whose values are equal and any could pair with another indice y to reach arg, create only one pair utilizing y, and choose indice a, b, or c based on which indice pair's sum is the smallest.
2) Only keep one pair if you find multiple pairs with matching numerical values that all came from unique indices. Determine which pair to keep based on which pair's indice sum is smallest.

In both interpretations, it's applying the test of sum(indices) to multiple possible pairs with equal numeric elements but different indices.

The first interpretation is the intended interpretation given that it expects [0, 0, 0, 0, 1, 1] to return 10. Interpreted the second way that same array and arg would return 4. You would create two pairs of [0,1] (given elements can't be reused) and prune the pair whose indices equal 6.

I would suggest either including an example or new language to clarify that "It means that if there are two different ways to make a pair, then use the combination with the smallest index.", as ArielLeslie so put it so well on the forums.

Maybe: "If a single indice could be paired with multiple other indices containing the same numeric elements, return the pair with the smallest sum of indices. For example, pairwise([1, 1, 2], 3) creates a pair with 2 using the 1 at indice 0 rather than the 1 at indice 1, because 0+2 < 1+2. Once an element has been used, it cannot be reused to pair with another."

Browser Information

  • Browser Name, Version: Chrome, Version 64.0.3282.186 (Official Build) (64-bit)
  • Operating System: Windows 10
  • Mobile, Desktop, or Tablet: Desktop

Your Code




Screenshot

help wanted learn

Most helpful comment

@williamsb https://github.com/freeCodeCamp/freeCodeCamp/blob/staging/CONTRIBUTING.md should be of assistance in walking you through your first contribution.

All 4 comments

Hi @willimsbw thanks for reporting the issue. We will try to get this clarified in the beta curriculum.

@willimsbw, thank you for pointing this out. I remember having trouble with the wording of this problem when I was first going through the algorithm challenges.

I like the example at the bottom of your comment, especially as an addition to the already existing example. Perhaps the whole problem description could read:

Given an array arr, find element pairs whose sum equal the second argument arg and return the sum of their indices. Once an element has been used, it cannot be reused to pair with another.

If a single indice can be paired with multiple other indices containing the same numeric elements, return the pair with the smallest sum of indices. For example, pairwise([1, 1, 2], 3) creates a pair with 2 using the 1 at indice 0 rather than the 1 at indice 1, because 0+2 < 1+2.

If multiple pairs that have the same numeric elements but different indices are possible, return the smallest sum of indices. For example, pairwise([7, 9, 11, 13, 15], 20) returns 6. The pairs that sum to 20 are [7, 13] and [9, 11]. We can then write out the array with their indices and values:

Then the rest of the description can remain unchanged.

Would you you be interested in submitting a pull request for this? I would be happy to walk you through the process if you need some guidance. In beta, the file that contains this challenge is seed/challenges/08-coding-interview-questions-and-take-home-assignments/coding-interview-algorithm-questions.json.

I would be happy to make a pull request, but I would love a walkthrough - I've never done one before.

@williamsb https://github.com/freeCodeCamp/freeCodeCamp/blob/staging/CONTRIBUTING.md should be of assistance in walking you through your first contribution.

Was this page helpful?
0 / 5 - 0 ratings