FastPrepFibonacci Number

Fibonacci Number

Microsoft logoMicrosoft● MediumNEW GRADONSITE INTERVIEW
Learn

Problem statement

Return the nth Fibonacci number using zero-based indexing.

The sequence is defined by F(0) = 0, F(1) = 1, and F(n) = F(n - 1) + F(n - 2) for n >= 2.

Function

fibonacci(n: int) → long

Examples

Example 1

n = 0return = 0

The first Fibonacci value is defined as F(0) = 0.

Example 2

n = 10return = 55

The zero-based sequence begins 0,1,1,2,3,5,8,13,21,34,55.

Constraints

  • 0 <= n <= 91
  • The result fits in a signed 64-bit integer.

More Microsoft problems

See Microsoft hiring insights
public long fibonacci(int n) {
  // Write your code here.
}
n0
expected0
Checking account…