Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Dynamic Programming Example

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Dynamic Programming Example. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Airtel Payments Bank uses sequence-based calculations in parts of its transaction and rewards services. Given a non-negative integer n, compute the nth Fibonacci number modulo 1,000,000,007 using dynamic programming.

The Fibonacci sequence is defined as F(0) = 0, F(1) = 1, and F(n) = F(n - 1) + F(n - 2) for n >= 2.

Return F(n) % 1,000,000,007. Your solution should avoid recursion depth issues and should use constant extra space apart from a few variables.

Formal Specification

  • Input: An integer n.
  • Output: An integer equal to the nth Fibonacci number modulo 1,000,000,007.

Constraints

  • 0 <= n <= 10^7
  • Use modulo 1,000,000,007
  • Use iterative dynamic programming
  • Use O(1) auxiliary space

Function Signature

def fibonacci_mod(n):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output