44 lines
1.1 KiB
Markdown
44 lines
1.1 KiB
Markdown
# Nordhealth test
|
|
|
|
## Problem
|
|
|
|
Given an unsorted array A[]. The task is to print all unique pairs in the unsorted array with equal sum.
|
|
Note: Print the result in the format as shown in the below examples.
|
|
|
|
Examples:
|
|
```
|
|
Input: A[] = { 6, 4, 12, 10, 22, 54, 32, 42, 21, 11}
|
|
Output:
|
|
Pairs : ( 4, 12) ( 6, 10) have sum : 16
|
|
Pairs : ( 10, 22) ( 21, 11) have sum : 32
|
|
Pairs : ( 12, 21) ( 22, 11) have sum : 33
|
|
Pairs : ( 22, 21) ( 32, 11) have sum : 43
|
|
Pairs : ( 32, 21) ( 42, 11) have sum : 53
|
|
Pairs : ( 12, 42) ( 22, 32) have sum : 54
|
|
Pairs : ( 10, 54) ( 22, 42) have sum : 64
|
|
```
|
|
```
|
|
Input:A[]= { 4, 23, 65, 67, 24, 12, 86}
|
|
Output:
|
|
Pairs : ( 4, 86) ( 23, 67) have sum : 90
|
|
```
|
|
|
|
## Solution
|
|
|
|
Solution in `nordhealth_test/solution.py:51` (print_pairs_with_same_sum())
|
|
|
|
Tests for the inputs are defined it `tests/test_solution.py`
|
|
|
|
For package manager I am using poetry, so to activate venv:
|
|
- `poetry install`
|
|
- `poetry env activate`
|
|
|
|
## Running
|
|
to run the solution:
|
|
- `chmod +x ./nordhealth_test/solution.py`
|
|
- `./nordhealth_test/solution.py [path to input file]`
|
|
- Example: `./nordhealth_test/solution.py ./inputs/input1.txt`
|
|
|
|
To run the tests:
|
|
- `pytest tests/`
|