Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Implement Fibonacci Sequence

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

Your question is Implement 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

K-State applications may need short numeric sequences for demonstrations or test data. Given a nonnegative integer n, generate the first n values of the Fibonacci sequence, beginning with 0, 1.

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

Formal Specification

Implement fibonacci_sequence(n).

  • Input: An integer n, where 0 <= n <= 30.
  • Output: A list containing exactly the first n Fibonacci numbers, from F(0) through F(n - 1).
  • Return an empty list when n is 0.

Constraints

  • 0 <= n <= 30
  • The output contains exactly n integers
  • The sequence starts with 0, 1
  • Use integer arithmetic

Function Signature

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