Leaderboard
Showing:
Fibonacci Sum
Easy Accuracy: 31.66% Submissions: 1555 Points: 2

Given a number positive number N, find value of f0 + f1 + f2 + …. + fN where fi indicates i’th Fibonacci number.
Remember that f0 = 0, f1 = 1, f2 = 1, f3 = 2, f4 = 3, f5 = 5, …
Since the answer can be very large, answer modulo 1000000007 should be returned.

Example 1:

Input:
N = 3
Output:
4
Explanation:
0 + 1 + 1 + 2  = 4

Example 2:

Input :
N = 4
Output :
7
Explanation :
0 + 1 + 1 + 2 + 3 = 7


Your Task:
You don't need to read input or print anything. Your task is to complete the function fibSum() which takes an integer N as input parameter and returns the sum of all the Fibonacci number from F0 to FN.

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

 

Constraints:
1 <= N <= 100000

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.

Fibonacci Sum

Output Window