#3708

Longest Fibonacci Subarray

medium · 69.5% accepted · 53 likes · top 77%

array

Description

You are given an array of positive integers nums.

A Fibonacci array is a contiguous sequence whose third and subsequent terms each equal the sum of the two preceding terms.

Return the length of the longest Fibonacci subarray in nums.

Note: Subarrays of length 1 or 2 are always Fibonacci.

Solution