Fibonacci in the array
Basic Accuracy: 31.81% Submissions: 22 Points: 1

Given an array arr of size N, the task is to count the number of elements of the array which are Fibonacci numbers

Example 1:

Input: N = 9, arr[] = {4, 2, 8, 5, 20, 1, 
                              40, 13, 23}
Output: 5
Explanation: Here, Fibonacci series will 
be 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55. 
Numbers that are present in array are 
2, 8, 5, 1, 13

Example 2:

Input: N = 4, arr[] = {4, 7, 6, 25} 
Output: 0
Explanation: No Fibonacci number in 
this array.

 

Your Task:
This is a function problem. You don't need to take any input, as it is already accomplished by the driver code. You just need to complete the function checkFib() that takes array arr and integer N as parameters and returns the desired output.

 

Expected Time Complexity: O(N).
Expected Auxiliary Space: O(1).

 

Constraints:
1 ≤ N ≤ 106

 

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.