Question bank › Math
Dsa Math Medium

Fibonacci Sequence Up to N

Generate the Fibonacci sequence up to a given integer n. The Fibonacci sequence is defined as follows: F(0) = 0, F(1) = 1, F(n) = F(n-1) + F(n-2) for n > 1. Print the sequence in a single line, separated by spaces, without including numbers greater than n. Input: A single integer n. Output: The Fibonacci sequence up to n. Example: Input: 10 Output: 0 1 1 2 3 5 8

Key concepts

fibonaccisequencesiteration

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.