Given an array with positive number the task to find the largest subsequence from array that contain elements which are Fibonacci numbers
belongs to collection: Interview C++ coding problems/challenges | arrays
All Answers
total answers (1)
belongs to collection: Interview C++ coding problems/challenges | arrays
total answers (1)
Algorithm:
Now the most interesting is isFibo(n) function. It really looks like nasty to check whether a given number is Fibonacci or not. But mathematics has been such a nice boon that there exists a lovely relation between Fibonacci number and golden ratio, which actually resulted in a nice formula to check for a number whether Fibonacci number or not
If 5*n*n +4 or 5*n*n -4 is perfect square then n is a Fibonacci number. For details check over here: Search a Fibonacci number
Example with explanation:
C++ implementation
Output
need an explanation for this answer? contact us directly to get an explanation for this answer