Back to Practice Dashboard
Competitive ProgrammingEasy

Fibonacci Numbers

Learn how to solve the 'Fibonacci Numbers' problem. This detailed resource details brute force and optimized approaches.

Problem Statement

Easy

Write a function nth_fibonacci(n) that returns the nth Fibonacci number. Assume F(0) = 0 and F(1) = 1.

Constraints
  • 0 <= n <= 100

Examples

Example 1
Input
nth_fibonacci(9)
Output
34
Explanation

F(9) is computed as F(8) + F(7) = 21 + 13 = 34.

Example 2
Input
nth_fibonacci(0)
Output
0
Explanation

F(0) is 0.

Need a Hint?
Define subproblem states, establish the recurrence relation, and use memoization (top-down) or tabulation (bottom-up).
Edge Cases to Watch
  • Empty list or null input variables
  • Single item lists/arrays
  • Extremely large input bounds causing integer or stack overflow

Ready to Solve?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Open in Editor