|
The expression "sqrt(12) + sqrt(48)" can be simplified as follows:
sqrt(12) + sqrt(48) = sqrt(4*3) + sqrt(16*3)
= 2*sqrt(3) + 4*sqrt(3)
= 6*sqrt(3)
= sqrt(36*3)
= sqrt(108)
Given a list of integers, A,
return a second list of integers, B,
such that the sum of the square roots of the elements in B
equals the sum of the square roots of the elements in A.
B should contain as few elements as possible.
The list with the fewest elements is guaranteed to be unique.
The elements in your returned list B should be sorted
from smallest to largest.
A will be given as a int[]. Return B as a int[] also.
For example, given the integers { 9, 16, 25 }, the sum of the
square roots is 3 + 4 + 5, which is 12.
The sum of the square roots of the list { 121, 1 } is also 12,
but there is an even shorter list: { 144 }, which is the correct answer.
|
| { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50 } |
| Returns:
{ 13, 14, 15, 17, 19, 21, 22, 23, 26, 29, 30, 31, 33, 34, 35, 37, 38, 39, 41, 42, 43, 46, 47, 54, 63, 90, 99, 180, 300, 450, 784 } | |
|