Stack Bash - Master data structures and algorithms

Fibonacci Sequence

Easy
The 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) = 0
F(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. 1.FibonacciEasy
  2. 2.Unique pathsMedium
  3. 3.KnapsackMedium
  4. 4.Subset sumMedium
  5. 5.Power setMedium
  6. 6.Coin changeMedium
  7. 7.Word breakHard
  8. 8.Longest common subsequenceHard

Want to confidently pass your next coding interview?

Stack Bash helps new and veteran software engineers master data structures and algorithms for technical interviews.