Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Print Fibonacci Non-Recursively
00:00
5 left

Print Fibonacci Non-Recursively

EasyPython

Problem

An ESPN scorecard component needs a short Fibonacci sequence for an analytics visualization. Write a non-recursive function that generates the first n Fibonacci numbers, starting with 0 and 1.

Return the sequence as a list. The function must use iteration and must not call itself or use a recursive helper.

Formal Specification

  • Input: An integer n, representing the number of Fibonacci terms to generate.
  • Output: A list containing exactly n integers in Fibonacci order.
  • For n = 0, return an empty list.

Constraints

  • 0 <= n <= 30
  • The implementation must be non-recursive
  • Return exactly n Fibonacci terms
  • The sequence starts with 0 and 1

Function Signature

def fibonacci_sequence(n):
Interviewer

Your question is Print Fibonacci Non-Recursively. Start with the requirements in the Question tab.

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.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.