Created
April 6, 2021 13:21
-
-
Save christianb/e34d798e21da6b638a03906b115e127c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Write a function that takes in an integer n and returns the nth Fibonacci number. | |
* | |
* The Fibonacci sequence is defined as follows: the first number of the sequence is `0`, | |
* the second number is `1`, and the nth number is the sum of (n - 1)th and (n - 2)th numbers. | |
* | |
* Note: For the purpose of this question, n starts at 1, so `getNthFib(1) == 0` and `getNthFib(2) == 1` | |
* | |
* Sequence: 0, 1, 1, 2, 3, 5 , 8, 13, 21, ... | |
* | |
* Sample input: n = 2 | |
* Sample output: 1 | |
* | |
* Sample input: n = 6 | |
* Sample output: 5 | |
*/ | |
fun getNthFib(n: Int): Int { | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment