JavaScriptEasyNumbers10 min

Generate Fibonacci numbers

Return the first n Fibonacci numbers starting with 0, 1. All input is valid JSON satisfying the constraints; do not mutate the meaning of values through type coercion. Interviewers use this problem to assess generate each term from the preceding two.

Input

A JSON integer n.

Output

Print one compact JSON value: an array of integers.

Constraints

0 <= n <= 70; all results are exact JavaScript integers.

Example

Input

7

Output

[0,1,1,2,3,5,8]

Example 2 input

3

Output

[0,1,1]

Boundary case: Zero terms produce an empty array

Public test cases (2)

  • Input

    7

    Expected output

    [0,1,1,2,3,5,8]
  • Input

    2

    Expected output

    [0,1]
Hints (2)
  1. Keep two running values
  2. Zero terms produce an empty array

Target complexity: time O(n) · space O(n)

Your solution

Checking runner availability…

Reference solution

Sign in for solution
All JavaScript programs