Please enter your email address or userHandle.
A Padovan Sequence is a sequence which is represented by the following recurrence relation
P(N) = P(N-2) + P(N-3)
P(0) = P(1) = P(2) = 1
Given a number N, find the Nth number in this sequence.
Note: Since the output may be very large, compute the answer modulus 10^9+7.
N = 3
Explanation: P1 + P0 = P3
P1 = 1 and P0 = 1
N = 4
Explanation: P2 + P1 = P4
P2 = 1 and P1 = 1
You don't need to read input or print anything. Your task is to complete the function padovanSequence() which takes integer N as input parameter and return Nth number in Padovan Sequence.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
1 <= N <= 106
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.