Nth Fibonacci Number Problem Statement

Given an integer 'N', the task is to compute the N'th Fibonacci number using matrix exponentiation. Implement and return the Fibonacci value for the provided 'N'.

Note:

Since the calculated Fibonacci number can be large, return the result modulo 109 + 7.

Formula:
The Fibonacci number is calculated by the formula: F(n) = F(n-1) + F(n-2)
where F(1) = F(2) = 1.

Example:

Input:
N = 5
Output:
5
Explanation:

The Fibonacci sequence up to N=5 is [1, 1, 2, 3, 5]. Thus, the output is 5.

Constraints:

  • 1 <= T <= 100
  • 1 <= N <= 109
Input:
The first line contains an integer 'T', denoting the number of test cases. For each test case, a single integer 'N' is given, representing the integer for which the corresponding Fibonacci number is to be found.
Output:
Output a single integer for each test case, representing the N'th Fibonacci number modulo 109 + 7, with each test case's output on a new line.
Note:
You are not required to print anything; implement the function as specified.
Follow Up:
Can you optimize your solution to achieve a time complexity better than O(N)?
AnswerBot
4mo

Use matrix exponentiation to efficiently compute the Nth Fibonacci number modulo 10^9 + 7.

  • Implement matrix exponentiation to calculate Fibonacci numbers efficiently.

  • Use the formula F(n) = F(n-1) + F(n...read more

Help your peers!
Select
Add answer anonymously...

Walmart Software Developer interview questions & answers

A Software Developer was asked Q. How many languages do you know?
A Software Developer was asked Q. What are your strengths?
A Software Developer was asked Q. Can you explain Source Code Control (SCC)?

Popular interview questions of Software Developer

A Software Developer was asked 1mo agoQ1. Tell me about yourself.
A Software Developer was asked Q2. How many languages do you know?
A Software Developer was asked Q3. What are your strengths?
Walmart Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits