Pell Number
Easy Accuracy: 0.0% Submissions: 0 Points: 2

Pell numbers are numbers that are similar to the Fibonacci numbers and are generated by below formula
Pn = 2*Pn-1 + Pn-2
with seeds P0 = 0 and P1 = 1
Your task is to print Nth pell number.

 

Example 1:

Input:
N = 3
Output:
5
Explanation:
P0 = 0, P1 = 1, P2 = 2*1+0 = 2,
P3 = 2*2+1 = 5

Example 2:

Input:
N = 4
Output:
12
Explanation:
P0 = 0, P1 = 1, P2 = 2*1+0 = 2,
P3 = 2*2+1 = 5, P4 = 2*5+2 = 12

 

Your Task:
You don't need to read input or print anything. Your task is to complete the function getNthPell() which takes an Integer N as input and returns the answer modulo (109+7).

 

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

 

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.