Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Fibonacci Sequence Coding

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

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

Corteva Agriscience can use simple numerical sequences when modeling recurring growth patterns. Given a non-negative integer n, generate the first n values of the Fibonacci sequence.

The sequence is defined as F(0) = 0, F(1) = 1, and F(k) = F(k - 1) + F(k - 2) for k >= 2.

Formal Specification

Implement fibonacci(n):

  • Input: An integer n representing the number of sequence values to return.
  • Output: A list containing F(0) through F(n - 1) in order.
  • Return an empty list when n is 0.
  • Use an iterative approach that avoids recomputing earlier values.

Constraints

  • 0 <= n <= 100
  • n is an integer
  • Return exactly n values
  • The sequence starts with F(0) = 0 and F(1) = 1

Function Signature

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