Problem Statement |
| Using the operators '+', '-', '/', '*', and parentheses as many times as you wish, find expressions for the smallest and largest primes that use each element of values exactly once. A prime is an integer greater than 1 with no divisors except 1 and itself. Return a int[] with exactly two elements, where the first element is the smallest prime you can make, and the second is the largest. If no primes can be constructed, return an empty int[]. |
|
Definition |
| Class: | MixedUpPrimes | Method: | findPrimes | Parameters: | int[] | Returns: | int[] | Method signature: | int[] findPrimes(int[] values) | (be sure your method is public) |
|
|
|
|
Notes |
- | The division operator truncates its results. For example, 8/5 = 1. |
- | The given numbers cannot be concatenated. For example, 8 and 5 cannot be combined to form 85. |
|
Constraints |
- | values will contain between 1 and 6 elements, inclusive. |
- | Each element of values will be between 1 and 30, inclusive. |
|
Examples |
0) | |
| | Returns: {2, 3 } | We get 2 using 2*1. We get 3 using 2+1. |
|
|
1) | |
| | Returns: {2, 7 } | Here we use 3-2+1=2 and 3*2+1 = 7. |
|
|
2) | |
| |
3) | |
| |
4) | |
| |
5) | |
| |