Algorithms

Fibonacci

easyalgorithmsdprecursion
0:00

Problem

Return the n-th Fibonacci number where F(0) = 0, F(1) = 1, and F(n) = F(n-1) + F(n-2) for n > 1.

Your solution
Test results
Click Run tests to check your solution against the test cases.

About this challenge

Fibonacci is a easy algorithms coding challenge. It tests algorithmic thinking and complexity analysis — the kind of problem-solving that shows up constantly in technical interviews. Write your solution in the editor above, run it against the test cases, and get instant feedback — free, in your browser, no sign-up.

Show a hint & approach (spoiler)

Hint: Iterative bottom-up is O(n) time and O(1) space. Avoid naive recursion (exponential).

Keep practicing

Browse all coding challenges, or build intuition for the underlying concepts with the algorithm visualizers and the developer cheatsheets.