Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Generate Fibonacci Series

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Generate Fibonacci Series. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Write a program that generates the Fibonacci series for a given number of terms n. The Fibonacci series starts with 0, 1, and each next term is the sum of the previous two terms.

Implement a function that returns the first n Fibonacci numbers as a list.

Formal Specification

  • Input: An integer n
  • Output: A list of integers containing the first n Fibonacci numbers
  • If n <= 0, return an empty list.

Constraints

  • -10^4 <= n <= 10^4
  • If n <= 0, return an empty list
  • The output list must contain exactly n terms when n > 0

Function Signature

def fibonacci_series(n):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output