Given an array of **N** elements, the task is to find the longest subarray which is Fibonacci-like.

A Fibonacci-like sub-array is defined as an array in which:

A[i]=A[i-1]+A[i-2]where i>2 and, A[1] and A[2] can be anything.

**Examples:**

Input :N = 5, arr[] = {2, 4, 6, 10, 2}Output :4 The sub-array 2, 4, 6, 10 is Fibonacci like.Input :N = 3, arr[] = {0, 0, 0}Output :3 The entire array is Fibonacci-like.

**Approach:**

The idea is to observe that any array of length of less than or equal to 2 is Fibonacci-like. Now, for arrays of length greater than 2:

- Maintain a variable
**len**initialized to 2 and a variable**mx**to store the maximum length so far. - Start traversing the array from 3rd index.
- If the fibonacci like array can be extended for this index, i.e. if a[i] = a[i-1] + a[i-2]
- Then increment the value of variable
**len**by 1. - Otherwise reinitialize the variable
**len**to 2. - Store the maximum of mx and len in the variable mx for current iteration.

- Then increment the value of variable

Below is the implementation of the above approach: