values. Pick some of its elements (their positions in the array do not matter) and arrange them into a "mirror" row:
x, x², x⁴, …, x^m, …, x⁴, x², x
where m is a power of two (including m = 1, in which case the row is just x). Each number toward the middle is the square of the one before it; the middle appears once and every other value appears twice, symmetrically. For example, [2, 4, 16, 4, 2] and [5, 25, 5] qualify, while [2, 4, 8, 4, 2] does not.
Return the largest number of elements such a row can have.values=[3, 9, 81, 9, 3, 2] → 5
Lay out 3, 9, 81, 9, 3: each number toward the middle is the square of the previous one. The 2 does not fit.
values=[1, 1, 1, 1, 5] → 3
The ones form the mirror 1, 1, 1 (one squared is still one), but the length must be odd, so the fourth 1 is left out.
values=[6, 7, 49, 10] → 1
7, 49, 7 would need a second 7, which is missing. Only a one-number mirror is left.
values=[3, 9, 81, 9, 3, 2]
5
Run checks the first 3 tests in your browser. Submit checks all 59 tests on the server, hidden ones included.