X

DAYS

:

HOUR

:

MINS

:

SEC

Copied to Clipboard
Matrix Exponentiation
Medium Accuracy: 45.69% Submissions: 10930 Points: 4

Given an equation of the form f(n) = f(n-1) + f(n-2) where f(0) = 1, F(1) = 1 , the task is to find the nth term of this sequence.
 

Example 1:

Input: n = 3
Output: 3
Explanation: f(3) = f(2) + f(1) = 3

Example 2:

Input: n = 2
Output: 2
Explanation: f(2) = f(1) + f(0) = 2

 

Yout Task:
You don't need to read or print anything. Your task is to complete the function FindNthTerm() which takes n as input parameter and returns nth term mod 10^9+7 .


Expected Time Compelxity: O(log(n))
Expected Space Complexity: O(K) where K is constant.

 

Constraints:
1 <= n <= 109

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.

Matrix Exponentiation

Output Window