Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Non-Recursive Fibonacci

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

Your question is Non-Recursive Fibonacci. 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

Antra data engineering utilities may need predictable numeric sequences for validation and transformation steps. Implement a non-recursive 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

Implement fibonacci(n), where n is a non-negative integer representing the number of values to return. The function must return a Python list containing F(0) through F(n - 1). For n = 0, return an empty list. The implementation must not use recursion.

Constraints

  • 0 <= n <= 10^4
  • n is an integer
  • Recursion is not allowed
  • Return exactly n values

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