Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Longest Fibonacci Subarray

XPChallenge Points: 20
levelLevel: Medium

You are given an array of positive integers nums.
A Fibonacci subarray is a contiguous sequence of numbers where each element (starting from the third one) is the sum of the two preceding elements.
Your task is to find and return the length of the longest Fibonacci subarray in nums.
Note:
Subarrays of length 1 or 2 are always considered Fibonacci by default.

Example 1:

Input: nums = [2, 3, 5, 8, 13, 21, 4, 6]

Output: 6

Example 2:

Input: nums = [4, 5, 9, 14, 23, 37, 2]

Output: 6

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result