Explanation

558.Count the Calls Made by Naive Fibonacci

Easy
The naive recursive Fibonacci function calls itself twice for every value of 2 or more. Given n, return how many calls in total fib(n) makes, counting the first call. This is the standard example of exponential timeExponential Time O(2ⁿ)Work that multiplies with each extra unit of input — adding one to n roughly doubles (here ×1.6) the work.: every call branches into two, and the same subproblems are solved again and again. Exponential algorithms become unusable very quickly — fib(50) would need tens of billions of calls — which is why spotting and removing repeated work matters so much.

Example 1:

Input: n = 4

Output: 9

Example 2:

Input: n = 1

Output: 1

+ 5 hidden test cases run on Submit.

Constraints:

  • ●0 ≤ n ≤ 25

n =

4