N-th Fibonacci Number Problem Statement

Given an integer ‘N’, your task is to find and return the N’th Fibonacci number using matrix exponentiation.

Since the answer can be very large, return the answer modulo 10^9 + 7.

Formula:

F(n) = F(n-1) + F(n-2), 
Where, F(1) = F(2) = 1.

Example:

Input:
N = 5
Output:
5

Input:

The first line contains a single integer ‘T’ denoting the number of test cases to be run. Then the test cases follow. The first line of each test case contains a single integer ‘N’, representing the integer for which we have to find its equivalent Fibonacci number. 

Output:

For each test case, print a single integer representing the N’th Fibonacci number. Return the answer modulo 10^9 + 7. Output for each test case will be printed in a separate line. 

Constraints:

  • 1 <= T <= 10
  • 1 <= N <= 10^5
  • Time Limit: 1 sec.

Note:

You are not required to print anything; it has already been taken care of. Just implement the function. 

Follow Up:

Can you solve it in Time Complexity better than O(N)?
AnswerBot
2y

Find N-th Fibonacci number using matrix exponentiation and return modulo 10^9+7.

  • Implement a function to find N-th Fibonacci number using matrix exponentiation.

  • Return the answer modulo 10^9+7.

  • Use the f...read more

Help your peers!
Select
Add answer anonymously...

Capgemini Analyst interview questions & answers

An Analyst was asked 2mo agoQ. Write a Java function to calculate the factorial of a given number.
An Analyst was asked 2mo agoQ. Write HTML code to open a new tab by clicking a button.
An Analyst was asked 2mo agoQ. What do you know about cloud infrastructure?

Popular interview questions of Analyst

An Analyst was asked 2mo agoQ1. Write a Java function to calculate the factorial of a given number.
An Analyst was asked 2mo agoQ2. Write HTML code to open a new tab by clicking a button.
An Analyst was asked 2mo agoQ3. What do you know about cloud infrastructure?

Top HR questions asked in Capgemini Analyst

An Analyst was asked 5mo agoQ1. Are you ready to relocate?
An Analyst was asked 6mo agoQ2. How do you overcome stress?
An Analyst was asked 6mo agoQ3. Can you tell me about yourself?
Capgemini Analyst 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