values whose elements are numbered **starting from 1**.
Choose a non-empty group of positions such that the product of **any two** chosen positions is a perfect square (a group of one position always qualifies).
Return the largest possible sum of the elements in the chosen group.values=[3, 1, 4, 6, 2, 5, 2, 8] → 9
Positions 1 and 4: 1·4 = 4 is a square, sum 3 + 6 = 9. Positions 2 and 8: 2·8 = 16, sum 1 + 8 = 9. The two groups cannot be merged (1·2 = 2 is not a square). The answer is 9.
values=[2, 5, 7] → 7
No two positions multiply to a square, so a single element is taken: the largest one, 7.
values=[1, 1, 1, 1, 1, 1, 1, 1, 1] → 3
values=[3, 1, 4, 6, 2, 5, 2, 8]
9
Run checks the first 3 tests in your browser. Submit checks all 64 tests on the server, hidden ones included.