Back to Practice Dashboard
Python BasicsEasy
Fibonacci Series upto nth term
Learn how to solve the 'Fibonacci Series upto nth term' problem. This detailed resource details brute force and optimized approaches.
Problem Statement
Easy
Write a function fibonacci_series(n) that takes a non-negative integer n and returns a list containing the first n terms of the Fibonacci series. The Fibonacci series starts with 0 and 1, and each subsequent term is the sum of the two preceding terms. If n is 0, return an empty list.
Constraints
- •0 <= n <= 50
Examples
Example 1
Input
n = 6
Output
[0, 1, 1, 2, 3, 5]
Explanation
The first 6 Fibonacci terms: 0, 1, 1 (0+1), 2 (1+1), 3 (1+2), 5 (2+3).
Example 2
Input
n = 1
Output
[0]
Explanation
The first 1 term of the Fibonacci series is just [0].
Example 3
Input
n = 0
Output
[]
Explanation
With n=0, there are no terms to return.
Need a Hint?
Use simple arithmetic operators (like modulo `%`, division `//`), conditional checks, or loops to inspect number properties.
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.