Back to problems Sign in to unlock
Leetcode
Easy
Dynamic Programming
Recursion
Math
Fibonacci Number
Compute the n-th Fibonacci number in the sequence defined by the sum of the two previous terms.
Acceptance 0%
Problem Statement
Given a non-negative integer , return the -th Fibonacci number.
The Fibonacci sequence is defined as:
- for
This is a classic warm-up problem for practicing iterative computation, recursion, and dynamic programming.
Input Format
- One integer .
- is the index in the Fibonacci sequence.
Output Format
- Return a single integer: .
Constraints
- The exact upper bound is platform-specific and not relied upon here.
- Use a solution that is efficient enough for typical interview constraints.
Examples
Sample cases returned by the problem API.
Example 1
Input
n = 2
Output
1
Explanation
F(2) = F(1) + F(0) = 1 + 0 = 1.
Example 2
Input
n = 5
Output
5
Explanation
The sequence starts 0, 1, 1, 2, 3, 5, so F(5) = 5.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.
Guided hints
Editorial and discussion links
Concept map and variants
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.