Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Generate Fibonacci Sequence

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

Your question is Generate Fibonacci Sequence. 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

Generate the Fibonacci sequence.

Implement generate_fibonacci(n) to return the first n terms, starting with 0, 1. The input is a nonnegative integer, and the output must be a list of integers. Return an empty list when n is zero.

Constraints

  • 0 <= n <= 1000
  • The output contains exactly n integers
  • The sequence starts with 0, then 1 when n >= 2

Function Signature

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