Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Generate Fibonacci Series
00:00
5 left

Generate Fibonacci Series

EasyPython

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):
Interviewer

Your question is Generate Fibonacci Series. Start with the requirements in the Question tab.

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.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.