Fibonacci Sequence
EasyThe fibonacci sequence of a number
n
is the sum of the 2 previous numbers in the sequence.The first 10 numbers of the sequence are:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34
Mathematically speaking, the fibonacci sequence is:
F(n) = F(n - 1) + F(n - 2)
Note that the first two numbers in a fibonacci sequence are:
F(1) = 0F(2) = 1
Write a function that returns the fibonacci sequence of a number
n
.Try it first
Solution
8 Essential Recursion & Dynamic Programming Coding Interview Problems
Master Recursion & Dynamic Programming by trying the coding challenges below.
- 1.FibonacciEasy
- 2.Unique pathsMedium
- 3.KnapsackMedium
- 4.Subset sumMedium
- 5.Power setMedium
- 6.Coin changeMedium
- 7.Word breakHard
- 8.Longest common subsequenceHard