Nth Fibonacci Number Problem Statement

Calculate the Nth term in the Fibonacci sequence, where the sequence is defined as follows: F(n) = F(n-1) + F(n-2), with initial conditions F(1) = F(2) = 1.

Input:

The input consists of a single integer ‘N’ for each test case.

Output:

Return the Nth Fibonacci number for each test case.

Example:

Input:
N = 5
Output:
5
Explanation:

The Fibonacci sequence up to the 5th term is: 1, 1, 2, 3, 5. Hence, the 5th Fibonacci number is 5.

Constraints:

  • 1 <= N <= 10000
  • Input ‘N’ is a positive integer.
Note

You are required to implement the function and return the result. The focus is on calculating efficiently within the given time limit.

AnswerBot
1y

The program calculates the Nth Fibonacci number using a recursive formula.

  • The Fibonacci series starts with 1, 1, and each subsequent number is the sum of the two preceding numbers.

  • The program uses a r...read more

Help your peers!
Add answer anonymously...
Grey Orange Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

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

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter