LONGEST SUBARRAY



One have to find the longest subarray such that its element satisfies the following condition:

  x[i]=x[i‐ 1]+x[i-2]   

If more than one subarray of is found of maximum length one has to print the array which starts with the minimum element and if they are also same then the array with minimum second element and so on.   If no subarray is found one has to print ‐1. 

Input:

3, 5, 8, 2, 19, 12, 7, 11

Output:

2, 5, 7, 12, 19

No comments:

Post a Comment

DISTRIBUTE BOOKS | Code vita 2019

Problem Description  For enhancing the book reading, school distributed story books to students as part of the Children’s day celebration...