Skip to main content

Fibonacci Number

JUNIOR
AmazonApple

The Fibonacci numbers form a sequence, where each number is the sum of the two preceding ones, starting from 0 and 1.

Given n, calculate F(n).

  • F(0) = 0
  • F(1) = 1
  • F(n) = F(n - 1) + F(n - 2), for n > 1

Example:

Input: n = 4
Output: 3
Explanation: F(4) = F(3) + F(2) = 2 + 1 = 3

Examples:

Input 1:{"n":0}
Output 1:0
Input 2:{"n":1}
Output 2:1

Loading editor...

Run your code to see results

Click the Run button above