Problem
Write a function that returns the n-th Fibonacci number.
The Fibonacci sequence is defined as:
-
F(0)=0
-
F(1)=1
-
F(n)=F(n−1)+F(n−2)
for
n≥2
Requirements
-
Input: integer
n
(assume
n >= 0
).
-
Output: integer
F(n)
.
-
Discuss time/space complexity and how you would handle large
n
.
Follow-ups (if asked)
-
Avoid recursion stack overflow.
-
Optimize for time (e.g., better than
O(n)
) or for very large values.