X

DAYS

:

HOUR

:

MINS

:

SEC

Copied to Clipboard
Non Fibonacci Number
Easy Accuracy: 54.38% Submissions: 377 Points: 2

Given a positive integer N, your task is to print the Nth non Fibonacci number. The Fibonacci numbers are defined as:

Fib(0) = 0

Fib(1) = 1

for n >1, Fib(n) = Fib(n-1) + Fib(n-2)

Example 1:

Input: N = 5
Output: 10
Explaination: The first 5 non-fibonacci 
numbers are 4, 6, 7, 9, 10.

Example 2:

Input: N = 15
Output: 22
Explaination: The fibonacci numbers 
are 1, 2, 3, 5, 8, 13, 21, 34. Here 
22 becomes the 15th non-fibonacci 
number.

Your Task:
You do not need to read input or print anything. Your task is to complete the function nonFibonacci() which takes the value N and returns the Nth non-fibonacci number.

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

Constraints:
1 ≤ N ≤ 105

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.


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.

Non Fibonacci Number

Output Window