Please enter your email address or userHandle.
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)
Input: N = 5
Explaination: The first 5 non-fibonacci
numbers are 4, 6, 7, 9, 10.
Input: N = 15
Explaination: The fibonacci numbers
are 1, 2, 3, 5, 8, 13, 21, 34. Here
22 becomes the 15th non-fibonacci
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)
1 ≤ N ≤ 105
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Login to access your submissions.
Please choose 'ReadOnlyMode' if you needn't to 'Edit' the problem e.g. viewing OJ's solution, TestCase Files (TCFs), TimeLimit etc.