Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Fibonacci Series

Easy Acceptance 85.00% Points 20.00

Description: You are given a positive integer N. Your task is to generate and print the Fibonacci sequence up to N terms. Display all the terms in order on a single line, separated by spaces.

Examples
Example 1

Example 1

Input: n = 5

Output: 0 1 1 2 3

Explanation: Not Needed

Example 2

Example 2

Input: 7

Output: 0 1 1 2 3 5 8

Explanation: Not Needed

Hints
Hint 1
N/A
Constraints
  • Constraints: 1<=N<=109
Companies
Microsoft Samsung Deloitte
Topics
Recursion
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions