Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Coding: Fibonacci Implementation

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

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

TikTok Shop may use simple numerical sequences when prototyping ranking or pacing logic. Implement a function that returns the first n Fibonacci numbers in order.

The Fibonacci sequence is defined 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 n integers: [F(0), F(1), ..., F(n - 1)]. For n = 0, return an empty list. You may assume results fit within Python's integer representation.

Constraints

  • 0 <= n <= 1000
  • The returned list must contain exactly n integers
  • F(0) = 0 and F(1) = 1
  • Use an iterative approach

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