Bootcamps
Masterclasses
Menu
Courses
Account
Login / Sign Up

Fibonacci Series (Tree Recursion)

Medium Acceptance 60% Points 30

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.

Examples
Example 1

Example 1

Input: N = 5

Output: 5

Explanation: 0 1 1 2 3 5 ? the 5th Fibonacci number is 5.

Example 2

Example 2

Input: N = 7

Output: 13

Explanation: 0 1 1 2 3 5 8 13 ? the 7th Fibonacci number is 13.

Example 3

Example 3

Input: N = 0

Output: 0

Explanation: Base case returns 0.

Constraints
  • 0 = N = 30
Topics
Recursion
Companies
Microsoft
Added 19 Jul 2026 60% acceptance
Ln 1, Col 1Sign in to save your code
2
1