Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Fibonacci Number

Easy

Topics
MathDynamic ProgrammingRecursion

The Fibonacci numbers satisfy F(0)=0, F(1)=1, and F(n)=F(n-1)+F(n-2) for n > 1. Given n, return F(n).

Example 1

Input:  n = 2
Output: 1

Example 2

Input:  n = 4
Output: 3

Constraints

  • 0 <= n <= 30
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access