dp
to store the length of the longest subsequence ending with elements at indices i
and j
.(i, j)
where i < j
.(i, j)
, search for an index k
such that arr[i] + arr[j] == arr[k]
using binary search or a set.k
exists, update dp[j, k]
to be dp[i, j] + 1
or 3
if (i, j)
is not in dp
.0
if no Fibonacci-like subsequence is found.