dsa · easy
Nth Fibonacci Number
GreyOrangeMathRecursionDynamic ProgrammingFoundation
Return the n-th Fibonacci number. F(0)=0, F(1)=1, F(n)=F(n-1)+F(n-2).
Arguments
n— the Fibonacci index; F(0)=0, F(1)=1, F(n)=F(n-1)+F(n-2)
**Example:** n = 6 → 8.
Constraints
0 <= n <= 30 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: 2 Expected: 1
Example 2
Input: 6 Expected: 8