Log In

The Fibonacci sequence is a series of numbers where the next number in the sequence is the sum of the previous 2 numbers.

The first two numbers in the sequence are 1 and 1.

The sequence starts with: 1, 1, 2, 3, 5, 8...

We would like to write a simple recursive solution that returns the nth Fibonacci number.

For example, fibonacci(4) would return 3, and fibonacci(6) would return 8.

Here is the pseudocode for the simple recursive solution:

fibonacci(n):
  if n is 1 or 2:
    return 1
  return fibonacci(n-1) + fibonacci(n-2)
Sign Up or Log In to access the code editor and answer the question!
Log In