x₁, x₂, …, xₘ a sum chain if it has at least 3 elements and every element from the third on equals the sum of the two before it: xᵢ + xᵢ₊₁ == xᵢ₊₂.
You get a strictly increasing array of positive integers values. Return the length of the longest subsequence of values that is a sum chain, or 0 if there is none.
A subsequence is what remains after deleting any elements while keeping the rest in order.values=[2, 3, 4, 5, 7, 9, 12, 20] → 4
[2, 5, 7, 12] works: 2 + 5 = 7 and 5 + 7 = 12, length 4. No longer chain exists.
values=[1, 4, 10, 30] → 0
No number equals the sum of two earlier picks, so the answer is 0.
values=[1, 2, 3, 5, 8] → 5
values=[2, 3, 4, 5, 7, 9, 12, 20]
4
Run checks the first 3 tests in your browser. Submit checks all 124 tests on the server, hidden ones included.