Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Writing Fibonacci Function

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

Your question is Writing Fibonacci Function. 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

State Street analytics workflows may use Fibonacci-like sequences for testing numerical pipelines. Write a function that returns the first n numbers in the Fibonacci sequence.

Define the sequence as F(0) = 0, F(1) = 1, and F(k) = F(k - 1) + F(k - 2) for k >= 2.

Formal Specification

Given a non-negative integer n, return a list containing exactly the first n Fibonacci numbers, starting with F(0). For n = 0, return an empty list.

Constraints

  • 0 <= n <= 10^4
  • Return exactly n Fibonacci values
  • Use Python integers for the results

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