Leaderboard
Showing:
Handle Score
@Ibrahim Nash 5725
@blackshadows 5685
@akhayrutdinov 5111
@mb1973 4989
@Quandray 4908
@saiujwal13083 4156
@sanjay05 3762
@marius_valentin_dragoi 3511
@sushant_a 3453
@KshamaGupta 3318
@the_coder95 3302
Complete Leaderboard
Non Fibonacci Number
Easy Accuracy: 30.19% Submissions: 53 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

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