mirror of https://github.com/01-edu/public.git
fix(findpairs) add more info and make it harder
This commit is contained in:
parent
74cbc9fb07
commit
cd19cd71b2
|
@ -1,4 +1,4 @@
|
||||||
## Find Pairs with Sum
|
## Find Pairs
|
||||||
|
|
||||||
### Instructions
|
### Instructions
|
||||||
|
|
||||||
|
@ -6,16 +6,18 @@ Write a program that finds all pairs of elements in an integer array that sum up
|
||||||
|
|
||||||
In this exercise you must take in consideration the following:
|
In this exercise you must take in consideration the following:
|
||||||
|
|
||||||
- Ensure its possible to have positive or negative integers in the array
|
- Ensure it's possible to have positive or negative integers in the array.
|
||||||
- Ensure each element is used only once in a pair
|
- Ensure each element is used only once in a pair, although the element can be repeated in different pairs.
|
||||||
- Allow for multiple pairs to sum up to the target value
|
- Allow for multiple pairs to sum up to the target value.
|
||||||
- Return the message "No pairs found." when no pair is present
|
- The output messages should follow the one given in the examples bellow.
|
||||||
- Return the message "Invalid target sum." if the target is invalid
|
- Return the message **"No pairs found."** when no pair is present.
|
||||||
- Return the message "Invalid number." if the number in the array is invalid
|
- Return the message **"Invalid target sum."** if the target is invalid.
|
||||||
|
- Return the message **"Invalid number: <number>"** if the number in the array is invalid.
|
||||||
|
- For any input format that deviates from the specified format `"[1, 2, 3, 4, 5]" "6"`, the program will return an "Invalid input." error message.
|
||||||
|
|
||||||
Let's consider the input `arr = [1, 2, 3, 4, 5]` and the target sum `targetSum = 6`. When we run the program, the `findPairs()` function will search for pairs in the array that sum up to `targetSum`.
|
Let's consider the input `arr = [1, 2, 3, 4, 5]` and the target sum `targetSum = 6`. When we run the program, the `findPairs()` function will search for pairs in the array that sum up to `targetSum`.
|
||||||
|
|
||||||
The expected output for this input will be:
|
Here is some example of outputs:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
$ go run . "[1, 2, 3, 4, 5]" "6"
|
$ go run . "[1, 2, 3, 4, 5]" "6"
|
||||||
|
@ -24,9 +26,15 @@ $ go run . "[-1, 2, -3, 4, -5]" "1"
|
||||||
Pairs with sum 1: [[0 1] [2 3]]
|
Pairs with sum 1: [[0 1] [2 3]]
|
||||||
$ go run . "[1, 2, 3, 4, 5]" "10"
|
$ go run . "[1, 2, 3, 4, 5]" "10"
|
||||||
No pairs found.
|
No pairs found.
|
||||||
|
$ go run . "[-1, -2, -3, -4, -5]" "-5"
|
||||||
|
Pairs with sum -5: [[0 3] [1 2]]
|
||||||
$ go run . "[1, 2, 3, 4, 20, -4, 5]" "2 5"
|
$ go run . "[1, 2, 3, 4, 20, -4, 5]" "2 5"
|
||||||
Invalid target sum.
|
Invalid target sum.
|
||||||
$ go run . "[1, 2, 3, 4, 20, p, 5]" "5"
|
$ go run . "[1, 2, 3, 4, 20, p, 5]" "5"
|
||||||
Invalid number: p
|
Invalid number: p
|
||||||
|
$ go run . "[1, 2, 3, 4" "5"
|
||||||
|
Invalid input.
|
||||||
|
$ go run . "1, 2, 3, 4" "5"
|
||||||
|
Invalid input.
|
||||||
$
|
$
|
||||||
```
|
```
|
||||||
|
|
Loading…
Reference in New Issue