Problem Statement | |||||||||||||
You wish to group a list of numbers into pairs such that the sum of each pair is prime. For example, given the numbers { 1, 4, 7, 10, 11, 12 }, you could group them as follows:
or:
Given a int[] numbers, return a int[] of all the elements in numbers that could be paired with numbers[0] successfully as part of a complete pairing, sorted in ascending order. Note that in the example above, even though 1 + 12 is prime, there would be no way to pair the remaining 4 numbers. So the answer for the example above would be { 4, 10 }. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
- | A prime number is a number divisible only by 1 and itself. | ||||||||||||
Constraints | |||||||||||||
- | numbers will contain an even number of elements, between 2 and 50, inclusive. | ||||||||||||
- | Each element of numbers will be between 1 and 1000, inclusive. | ||||||||||||
- | Each element of numbers will be distinct. | ||||||||||||
Examples | |||||||||||||
0) | |||||||||||||
| |||||||||||||
1) | |||||||||||||
| |||||||||||||
2) | |||||||||||||
| |||||||||||||
3) | |||||||||||||
| |||||||||||||
4) | |||||||||||||
|