Submissions disabled: This deployment is running in read-only mode for safety. Code execution is not available here.
← Back to all problems
Easy

Fibonacci Number

Updated Jan 31, 2026

Problem

Given an integer n, output the nth Fibonacci number.

The Fibonacci sequence is: 0, 1, 1, 2, 3, 5, 8, 13, 21, ...

where F(0) = 0, F(1) = 1, and F(n) = F(n-1) + F(n-2) for n > 1.

Constraints

0 <= n <= 30

Examples

Example 1

Input: n = 0
Output: 0

Example 2

Input: n = 1
Output: 1

Example 3

Input: n = 10
Output: 55

Function Signature

def fib(self, n: int) -> int

How to Submit

Implement a Solution class with a fib method.

Your method will be called with the input parameters and should return the answer.