Timer is Running

The Nth Fibonnaci
Submissions: 77   Accuracy:

11.7%

  Difficulty: Easy   Marks: 2
Associated Course(s):   Interview Preparation

Given a positive integer N, find the last digit of the Nth term from the Fibonacci series.
 

Example 1:

Input:
N = 5
Output:
5
Explanation:
5th Fibonacci number is 5

Example 2:

Input:
N = 14
Output:
7
Explanation:
14th Fibonacci number is 377
It's last digit is 7


Your Task:
You don't need to read input or print anything. Your task is to complete the function fib() which takes an integer N as input parameter and returns the last digit of Nth Fibonacci number.


Expected Time Complexity: O(N)
Expected Space Complexity: O(1)

 

Constraints:
1 <= N <= 1000

** For More Input/Output Examples Use 'Expected Output' option **

Author: Rohan Malhotra


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.