← Coding round practice

Fibonacci using Recursion

MediumRecursion

The problem

Compute the nth Fibonacci number using plain recursion (fib(0)=0, fib(1)=1).

Sample input

10

Sample output

55
Show the solution · 8 languages
fun fib(n: Int): Int {
    if (n < 2) return n
    return fib(n - 1) + fib(n - 2)
}

fun main() {
    println(fib(10))
}