You are given a positive integer N. Your task is to compute the Nth Fibonacci number using tree recursion, where each function call makes two recursive calls to compute the previous two Fibonacci values.
The Fibonacci sequence follows:
F(0) = 0, F(1) = 1
F(n) = F(n-1) + F(n-2)
Return the value of the Nth Fibonacci number.
Example 1
Input: N = 5
Output: 5
Explanation: 0 1 1 2 3 5 ? the 5th Fibonacci number is 5.
Example 2
Input: N = 7
Output: 13
Explanation: 0 1 1 2 3 5 8 13 ? the 7th Fibonacci number is 13.
Example 3
Input: N = 0
Output: 0
Explanation: Base case returns 0.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
2
1
3
2