You will be given a string of digits that supposedly come from three prime numbers.
The digits will be given in a random order.
Your task is to find the three prime numbers, if they exist.
If there are three such primes, return them sorted least to greatest.
If there is more than one possible set of three primes, return the set with the smallest product.
If there is no such set, return { }.
For example, the five digits of the primes 5, 13, and 19 could be given to you as "39151".
There are several other sets of prime numbers that could also be rearranged to give this input,
for example { 5, 31, 19 } and { 3, 11, 59 }.
The set with the smallest product is { 5, 13, 19 },
so those are the three primes your method should return.
Each digit of each prime will be present in the input. For example, if the input contains exactly two occurrences of the digit "1" (as in the example above), you must use the digit "1" exactly twice.
Any zeros in the input may not be used as leading zeros in any of the three primes.
|