Fibonacci Number - aloalgo

Fibonacci Number

Easy

You are given an integer n.

Your task is to calculate the n-th Fibonacci number, denoted F(n).

Remember that:

  • The Fibonacci sequence is a series of numbers in which each number is the sum of the two preceding ones.
  • The sequence is defined by the recurrence relation F(n) = F(n - 1) + F(n - 2).
  • The base cases are F(0) = 0 and F(1) = 1.

Return the n-th Fibonacci number.

Example 1

Input
2
Output
1
Explanation:

F(2) = F(1) + F(0) = 1 + 0 = 1.

Example 2

Input
3
Output
2
Explanation:

F(3) = F(2) + F(1) = 1 + 1 = 2.

Example 3

Input
4
Output
3
Explanation:

F(4) = F(3) + F(2) = 2 + 1 = 3.

Loading...
Input
2
Output
1

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!