The Fibonacci Number interview question asks you to calculate the number in the Fibonacci sequence. The sequence is defined as , and for . It's the most common entry point for learning about recursion and optimization.
This is a baseline question asked by almost every company, from J.P. Morgan to Meta. It evaluates your knowledge of Dynamic Programming interview pattern and your ability to optimize an exponential recursion into a linear or even logarithmic solution. It's often used to see if a candidate understands the concept of "memoization" or "space optimization."
There are three main levels of solution for this:
fib(n-1) + fib(n-2). Complexity: O(2^N).Find :
dp[n+1] when only the previous two numbers are needed.Always start with the iterative solution with space. It is the most practical and efficient for most interview contexts. If you want to impress, mention the closed-form "Binet's Formula" or the Matrix Exponentiation approach.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| N-th Tribonacci Number | Easy | Solve | |
| Climbing Stairs | Easy | Solve | |
| Different Ways to Add Parentheses | Medium | Solve | |
| Number of Digit One | Hard | Solve | |
| Least Operators to Express Number | Hard | Solve |